的HtmlUnit并不jQuery的升级,从1.7到1.8.1后正确重定向并不、重定向、正确、HtmlUnit

2023-09-10 18:34:08 作者:人不风流枉少年

我用2.10的HtmlUnit点击其触发的JavaScript重定向到另一个网址的链接。 JavaScript使用window.location的重定向。其结果是不一样的,如果我直接与URL打开页。重定向页面结果看起来好像页面仍在加载,但事实并非如此。

I'm using HtmlUnit 2.10 to click a link which triggers a JavaScript that redirects to another URL. JavaScript uses window.location to redirect. The result is not the same as if I open the page directly with the URL. The redirection page result looks as if the page is still loading, although it's not.

在查看请求发送它看起来好像请求的HtmlUnit的页面,甚至发送Ajax的请求从页面我想重定向到,但并没有表现出来。我试过IO写作page.asXml()到一个.html文件,以获得页的preVIEW,它包含了几乎任何东西,因为如果它仍在加载新的内容。但是,我也试着等待长达100秒的页面加载与

When looking at the requests sent it looks as if HtmlUnit requests the page and even send the ajax-requests FROM the page I'm trying to get redirected to, but does not show it. I've tried IO-writing "page.asXml()" into a .html file to get a preview of the page, and it contains almost nothing, as if it's still loading the new content. But, I've also tried waiting for up to 100 seconds for the page to load with

synchronized (page) {
   page.wait(int x);
}

和它没有任何差异的结果。

and it does not make any difference to the result.

我无法给出一个可再现脚本这个错误,因为该页面只在一瞬间本地运行。

I cannot give a reproducable script for this error since the page is run locally only at the moment.

有什么想法,什么可能是错的?

Any thoughts as to what can be wrong?

编辑:我可以补充一点,这个问题似乎与jQuery的1.7.0升级到1.8.1的jQuery到达

推荐答案

请确保您已设置Web客户端有它的 redirectEnabled 字段设置为真正的。要做到这一点,只需添加这行执行的请求之前...

Make sure you have set the WebClient to have it's redirectEnabled field set to true. To do this, simply add this line before you execute the request...

webClient.setRedirectEnabled(true);

这将确保重定向后跟化的HtmlUnit客户端。

This will ensure redirects are followed by the HtmlUnit client.

以下是文档的方法。