HtmlUnit 不等待 AJAX 执行
我正在尝试在 .Net 中使用无头浏览器,并且我需要它来执行 JavaScript,因为我需要用它读取的信息是通过 AJAX 加载的。经过一些研究,我相信我最好的选择是 HtmlUnit。我已按照 Steven Sanderson 博客 http://blog.stevensanderson.com/2010/03/30/using-htmlunit-on-net-for-headless-browser-automation/ 总的来说,这效果很好。然而,尽管我努力尝试,我还是无法让它等待 JavaScript 加载。本质上,在从选择框中选择某些内容后,AJAX 请求会触发并填充另一个选择框。 HtmlUnit 永远不会看到新选项。
我已经尝试了常见问题解答中所有示例的组合 http://htmlunit.sourceforge.net/ faq.html#AJAXDoesNotWork 所以我只能假设这是一个问题,因为它已经转换为在.Net 中运行。我希望有人在这方面有一些经验,可以阐明问题所在。我觉得我使用 HtmlUnit 的方式是正确的,并且之前已经在这里推荐过 是否有适用于 .NET 的无头浏览器(用于自动化 Web-UI 测试)? 和 无头互联网浏览器?但我已经走进了死胡同。
因此,如果有人对支持 JavaScript 的 headers 浏览器有更好的选择,并了解如何让 HtmlUnit 等待 JavaScript,甚至只是一些关于如何进一步调试的建议。
谢谢。
西蒙
I am trying to use a headless browser in .Net and I need it to execute JavaScript because the information I need to read with it is loaded via AJAX. After some research I believe my best option is HtmlUnit. I have followed the instructions in Steven Sanderson's blog http://blog.stevensanderson.com/2010/03/30/using-htmlunit-on-net-for-headless-browser-automation/ in the main this works great. However, as hard as I try I cannot get it to wait for the JavaScript to load. Essentially after selecting something from a selectbox an AJAX request fires and populated another selectbox. HtmlUnit never sees the new options.
I have tried combinations of all of the examples in the FAQ http://htmlunit.sourceforge.net/faq.html#AJAXDoesNotWork so I can only assume that it is a problem with the fact it has been converted to run in .Net. I am hoping someone has some experience in this who can shed some light on what is wrong. I feel like I am going the right way with HtmlUnit and it has been recommended on here before Is there a headless browser for .NET (for automated Web-UI-Tests)? and headless internet browser? but I have reached a dead end.
So if anyone has either a better choice for a headles browser that supports JavaScript, and ideas how to get HtmlUnit to wait for the JavaScript or even just some advice on how to debug this further.
Thanks.
Simon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要使用
webClient.waitForBackgroundJavaScript()
或webClient.waitForBackgroundJavaScriptStartingBefore()
。您还可以查看这些可能对您帮助不大的链接。
I think you need to use
webClient.waitForBackgroundJavaScript()
orwebClient.waitForBackgroundJavaScriptStartingBefore()
.You can also see these links that might help you little.