HtmlUnit 不加载外部引用的 javascript
我在尝试使用 HtmlUnit 测试 Web 应用程序时遇到了问题。请记住,我使用 HtmlUnit 的时间不长,所以我可能会错过一些琐碎的事情。
由于某种原因,外部引用的 javascript 没有被加载。当我将页面打印为 xml 时,我得到的只是:
<script language="javascript" src="urltofile.js">
</script>
如您所见,当脚本标签应包含 javascript 时,它是空的。我缺少什么?我整个早上都在谷歌上搜索解决方案,但没有找到任何相关信息。任何帮助将不胜感激!
I have run into a problem while trying to test a web application with HtmlUnit. Please bear in mind that I haven't used HtmlUnit very long so I might be missing something trivial.
For some reason externally referenced javascripts aren't being loaded. When I print the page as xml all i get is this:
<script language="javascript" src="urltofile.js">
</script>
As you can see the script tag is empty when it should contain the javascript. What am I missing? I have googled for a solution all morning but haven't found any relevant information. Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过很多个小时的谷歌搜索后,我发现解决方案非常简单。我所要做的就是在检索页面后等待几秒钟,以便在执行其他操作之前让 JavaScript 有一些时间执行。老实说,找到解决方案有点虎头蛇尾,但至少我现在可以继续处理更重要的事情了。 :)
After many many hours of googling I found the solution to be very simple. All I had to do was to wait a few seconds after the page is retrieved to allow the javascript some time to execute before doing anything else. I can honestly say finding the solution was a bit of an anticlimax, but at least I can move along to more important stuff now. :)
该标记加载一个外部文件:“urltofile.js”,因此没有任何内容并不奇怪,因为 js 代码是从该文件加载的,而不是注入到现有标记中。
That tag loads an external file: "urltofile.js", so it's not strange to have nothing into because the js code is loaded from that file and not injected into the existing markup.