HtmlUnit doesn't load externally referenced javascript

半城伤御伤魂 提交于 2019-12-01 09:33:02

问题


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!


回答1:


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. :)




回答2:


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.



来源:https://stackoverflow.com/questions/2848398/htmlunit-doesnt-load-externally-referenced-javascript

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