Given an HtmlUnit HtmlPage object, how do I get the URI of its Document?
The page object I have is the result of a long chain of click()
calls (just in case you were wondering how I could have a page object without knowing the URL used to obtain it).
- The method
HtmlPage.getDocumentURI
is not implemented. Htm开发者_如何学PythonlPage.getOwnerDocument
returns null.page.executeJavaScript("return document.location").getJavaScriptResult()
also returns null.
Any hints?
The answer is of course to realize that executeJavaScript
should have been called evalJavaScript
, and write something like
page.executeJavaScript("document.location").getJavaScriptResult()
page.getUrl()
worked fine for me.
精彩评论