HTMLUnit无法在滚动时提供更新的页面

时间:2014-02-24 06:54:05

标签: htmlunit

我正在尝试从动态附加数据的页面获取数据。

规格: HTMLUnit:版本:2.14

但滚动后我无法获得新页面。我尝试使用各种浏览器版本和所有可能的代码更改。如果有人能让我知道我做错了什么就会很棒。 此外,document.documentElement.scrollTop;始终返回零。

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

HtmlPage page = webClient.getPage("http://www.snapdeal.com/products/mobiles-mobile-phones/?q=Brand:Samsung");
System.out.println(page.getTitleText());
final String pageAsXml = page.asXml();
System.out.println("Page1=\n" + pageAsXml);         
String s = "window.scrollBy(0, window.innerHeight);document.documentElement.scrollTop;";
ScriptResult sr = page.executeJavaScript(s);
JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager();

while (manager.getJobCount() > 4) {
    System.out.println("SCript Job count = " + manager.getJobCount());
    Thread.sleep(1000);
}
System.out.println("Result= " + sr.getJavaScriptResult() + "\n");

HtmlPage page2 = (HtmlPage) sr.getNewPage();
if(page == page2)
    System.out.println("No difference");
else
    System.out.println("Page2\n" + page2.asXml());

谢谢&此致

Reeni

0 个答案:

没有答案