Given the HtmlUnit HtmlPage object, how do I get the URI of my document?

The page object that I have is the result of a long chain of calls click()(in case you are wondering how I could have a page object without knowing the URLs used to get it).

  • The method is HtmlPage.getDocumentURInot implemented.
  • HtmlPage.getOwnerDocument returns null.
  • page.executeJavaScript("return document.location").getJavaScriptResult() also returns null.

Any clues?

+3
source share
2 answers

The answer, of course, is what you executeJavaScriptshould name evalJavaScriptand write something like

page.executeJavaScript("document.location").getJavaScriptResult()
+2
source
page.getUrl()

worked great for me.

+1
source

Source: https://habr.com/ru/post/1790472/


All Articles