Search code examples
javahtmlunit

How to find out if an HtmlPage has finished executing all JavaScript(s) (Java htmlunit 2.24)


I'm using Java htmlunit 2.24 library. Is there anyway to find out that any JavaScript has actually finished executing on an HTML page (HtmlPage)?


Solution

  • Yes there is....

    final JavaScriptJobManager tmpJobManager = aHtmlPage.getEnclosingWindow().getJobManager();
    
    int tmpJobCount = tmpJobManager.getJobCount();
    if (tmpJobCount > 0) {
      .....
    }
    

    If you are interested in more details you can have a look at the Wetator (http://www.wetator.org/) source code (https://wetator.repositoryhosting.com/trac/wetator_wetator/browser/trunk/wetator/src/org/wetator/backend/htmlunit/HtmlUnitBrowser.java)