title: Get the changed HTML content after it's updated by Javascript? (htmlunit)
body: <p>I'm having some trouble figuring out how to get the content of some HTML <em>after</em> javascript has updated it.</p>
  <p>Specifically, I'm trying to get the current time from <a href="http://tycho.usno.navy.mil/what.html" rel="noreferrer">US Naval Observatory Master Clock</a>. It has an <code>h1</code> element with the <code>ID</code> of <code>USNOclk</code> in which it displays the current time.</p>
  <p>When the page first loads, this element is set to display &quot;Loading...&quot;, and then javascript kicks in and updates it to the current time via</p>
  <pre><code>function showTime()
      {
          document.getElementById('USNOclk').innerHTML=&quot;Loading...&lt;br /&gt;&quot;;
          xmlHttp=GetXmlHttpObject();
          if (xmlHttp==null){
              document.getElementById('USNOclk').innerHTML=&quot;Sorry, browser incapatible. &lt;BR /&gt;&quot;;
              return;
          } 
          refresher = 0;
          startResponse = new Date().getTime();
          var url=&quot;http://tycho.usno.navy.mil/cgi-bin/time.pl?n=&quot;+ startResponse;
          xmlHttp.onreadystatechange=stateChanged;
          xmlHttp.open(&quot;GET&quot;,url,true);
          xmlHttp.send(null);
      }  
  </code></pre>
  <p>So, the problem is that I'm not sure how to get the updated time. When I check the element, I see the &quot;Loading...&quot; as the content of the <code>h1</code> element.</p>
  <p>I've double checked that javascript is enabled, and I've tried calling the <code>waitForBackgroundJavaScript</code> function on the <code>webclient</code> as well hoping that it would give the javascript time to start updating stuff. However, no success as of yet.</p>
  <h3>My Current Code:</h3>
  <pre><code>import com.gargoylesoftware.htmlunit._
  import com.gargoylesoftware.htmlunit.html.HtmlPage
  
  object AtomicTime {
  
    def main(args: Array[String]): Unit = {
      val url = &quot;http://tycho.usno.navy.mil/what.html&quot;
      val client = new WebClient(BrowserVersion.CHROME)
      
      println(client.isJavaScriptEnabled()) // returns true
      client.waitForBackgroundJavaScript(10000)
  //    client.waitForBackgroundJavaScriptStartingBefore(10000) //tried this one too without success
      var response: HtmlPage = client.getPage(url)
      println(response.asText())
    }
  }
  </code></pre>
  <p>How do I trigger the javascript to update the HTML?</p>