質問

When I used HttpUnit, I would invoke getCurrentPage() method of HttpUnit to get the current page. How can I do that in HtmlUnit? I tried webclient.getHomePage(), but it seem to return wesite of htmlunit.

One suggestion I got is use getPage using previous URL, but that doesn't work for me because I need to refactor a code that is earlier written in a code which makes it impossible reexecute previous request.

役に立ちましたか?

解決

You can use the following approach to get HtmlPage object from webclient assuming you already navigaed to a page either by using wc.getPage(url) or submitting a form in previous page or using any other method. Assuming that wc is the WebClient object.

HtmlPage currentPage = (HtmlPage) wc.getCurrentWindow().getEnclosedPage();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top