Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlUnit - dynamically loaded JavaScript not running

Tags:

htmlunit

I'm trying to write some automated tests of a website using HtmlUnit. Our web pages load two JavaScripts, one of which then loads several other JavaScripts dynamically into the DOM. These JavaScripts then do some UI initialization. My problem is that HtmlUnit updates the DOM with the new JavaScripts, but does not then seem to run those JavaScripts, because expected DOM elements do not appear.

Here are some things I tried:

  1. Viewing the page with toXml(). The page.toXml() method shows the JavaScripts added, but not the expected UI elements.
  2. Testing for the presence of expected DOM elements. These show up in a real web browser, and I can use jquery and firebug together to confirm that they are there.
  3. Trying to manually start the JavaScripts through the executeJavaScript. When I do this, it can find the method I'm invoking directly, but that method cannot find symbols in other JavaScripts.

Has anyone else ran into this issue?

like image 743
James Kingsbery Avatar asked Nov 15 '22 11:11

James Kingsbery


1 Answers

Did you try to insert a short pause after loading the page?

like image 94
nici Avatar answered Dec 31 '22 07:12

nici