如何在 HtmlUnit 中模拟浏览器的后退按钮?
我还没有找到一个清晰而明显的建议来模拟 HtmlUnit 中浏览器的“后退”按钮。你做过这个吗?如果是这样,怎么办?
我想出的最好的办法是在当前页面上执行 javascript:
ScriptResult result = currentPage.executeJavaScript("javascript:window.history.back();");
currentPage = (HtmlPage)result.getNewPage();
是否有建议的方法使用 htmlunit 返回历史上的一页?返回上面的代码会产生什么影响?虽然我还没有说服自己 HtmlUnit 实际上能够准确模拟不同浏览器的 javascript 解释,但是我距离使用 HtmlUnit 的全部功能来使用上述代码模拟浏览器的后退按钮还有多远呢?有没有比这更好地模拟浏览器后退按钮的方法?
另外,我注意到 HtmlUnit 中的 History 类,但它似乎毫无价值。想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能我有点晚了,但这对其他人也可能有用。您可以通过访问 WebWindow 的历史记录来返回历史记录,如下所示:
还有其他有用的方法。您可以在此处查看 API。
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:
There are other useful methods too. You can take a look at the API here.