Question

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.

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top