I have not found a clear and obvious suggestion to emulate the browser's 'Back' button in HtmlUnit. Have you done this? If so, how?
The best thing I've come up with is to execute javascript on the current page:
ScriptResult result = currentPage.executeJavaScript("javascript:window.history.back();");
currentPage = (HtmlPage)result.getNewPage();
Is there a suggested method to go back one page in history with htmlunit? What are the implications of going back with the above code? While I haven't convinced myself that HtmlUnit actually does any accurate emulation of different browsers' javascript interpretation, how close do I come to using HtmlUnit's full capacity to emulate a browser's back button using the above code? Is there a way to get a better emulation of a browser's back button than this?
Also, I've noticed the History class in HtmlUnit, but it seems pretty worthless. Thoughts?
Probably I'm a bit late, but this might be useful for others too. You can go back in history by accessing the history of the WebWindow like this:
webClient.getWebWindows().get(0).getHistory().back();
There are other useful methods too. You can take a look at the API here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With