开发者

How to force HtmlUnit to save page?

I'm using HtmlUnit to click on a HtmlElement that triggers Javascript action:

currentPage = ((HtmlElement) currentPage.get开发者_运维知识库ByXPath("//*[contains(@onclick, 'check();')]").get(0)).click();

The element is:

<a href="#" onclick="check(); return false;">

The page returned is quite similar to the page, containing that element: same URL, mostly same HTML, but there are some minor differences in the HTML and HtmlUnit doesn't save the new page. I'm using HttpAnalyzer to sniff the traffic and I see that the Webclient correctly handles JS and send the right request. The response is also correct, but when I dump the contents of the currentPage to a file, I see that the actual page didn't change. How can I fix it?


I had the same problem. In my case it was:

<div id="loginButton" class="buttonOuter" onclick="this.childNodes[1].click();">
<div class="buttonInner">
<a href="#">Login</a>
</div>
<input class="loginHiddenButton" type="submit" onclick="submit_proc(false,'')">
</div>

I solve it this way:

HtmlPage page1 = webClient.getPage("myURI");
HtmlElement htmlElement = (HtmlElement) page1.getByXPath("loginHiddenButtonXPATH").get(0);

webClient.setJavaScriptEnabled(false);
page1 = htmlElement.click();
webClient.setJavaScriptEnabled(true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜