Process AJAX request in Htmlunit

心已入冬 提交于 2019-12-01 04:00:33

For me it helped to use htmlunit 2.15 with NicelyResynchronizingAjaxController, and also

webClient.getOptions().setThrowExceptionOnScriptError(false);

My full setup is

    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());

I would try the solution of setting

webClient.setAjaxController(new NicelyResynchronizingAjaxController());

this would cause all ajax calls to be synchronous.

Alternatively, did you try in your solution to call to "webClient.waitForBackgroundJavaScript(10000)" after tou got the page?

Something like this:

final HtmlPage page2 = button.click();
webClient.waitForBackgroundJavaScript(10000)
String originalHtml = page2.asXml();
return originalHtml;

Please use also htmlunit 2.13

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!