I am having trouble figuring out how to get the contents of some HTML after javascript has updated it.
In particular, I am trying to get the current time from the US Navy Master Clock . It has an element h1 with ID of USNOclk , which displays the current time.
When the first page loads, this element is set to display "Loading ..." and then javascript launches and updates it to the current time using
function showTime() { document.getElementById('USNOclk').innerHTML="Loading...<br />"; xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ document.getElementById('USNOclk').innerHTML="Sorry, browser incapatible. <BR />"; return; } refresher = 0; startResponse = new Date().getTime(); var url="http://tycho.usno.navy.mil/cgi-bin/time.pl?n="+ startResponse; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); }
So the problem is that I'm not sure how to get the updated time. When I check the element, I see "Loading ..." as the content of the h1 element.
I double-checked that javascript is enabled, and I tried calling the waitForBackgroundJavaScript function in the webclient , and also hoping this would give javascript time to start the update. However, there is no success yet.
My current code is:
import com.gargoylesoftware.htmlunit._ import com.gargoylesoftware.htmlunit.html.HtmlPage object AtomicTime { def main(args: Array[String]): Unit = { val url = "http://tycho.usno.navy.mil/what.html" val client = new WebClient(BrowserVersion.CHROME) println(client.isJavaScriptEnabled())
How can I activate javascript to update HTML?
source share