HtmlUnit JavaScript事件 [英] HtmlUnit javascript event

查看:161
本文介绍了HtmlUnit JavaScript事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功在SITE上使用HtmlUnit登录,运行了表单搜索并获得了包含结果的页面.现在在现实世界中,要获得整个页面的结果,我需要滚动页面更多次.但是我正在使用HtmlUnit,然后我已经完成了:

I successfull done login with HtmlUnit on SITE, run a form search and got a page with results. Now in real world, to get the whole page result I need to scroll the page more times . But I am using HtmlUnit ,then I have done :

List<DIV> res=page.getByXPath(...) // got 13 items
ScriptResult res=page.executeJavaScript("window.scrollBy (0,2000);");
res=page.getByXPath(...) // would get other items,same query as the first

问题在于,在上面的代码返回与运行JS之前相同的项目之后,页面上的查询返回的结果与XPath查询相同.相反,在浏览器上,滚动效果很好,并返回结果项目的seconf列.那么,HtmlUnit不是为此设计的吗?一个错误?还是还有另一个HtmlUnit技巧?

The problem is that the query on page , after the above code is returning the same items as before run JS , the XPath query return same result items . Instead ,on browser, the scroll work well and return the seconf train of result items. Then , does HtmlUnit is not designed for this ? a bug ? or there is another HtmlUnit trick?

我也尝试过

ScriptResult res =page.getBody().fireEvent("scroll");

谢谢

推荐答案

由于HtmlUnit是无头浏览器,因此滚动支持仍然很弱.请在gitub上打开一个与此相关的问题(包括示例代码),如果可能,我会尝试改善支持.

As HtmlUnit is a headless browser, the scrolling support is still weak. Please open an issue at gitub about this (including sample code) and i will try to improve the support if possible.

这篇关于HtmlUnit JavaScript事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆