Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>These are pulled directly from the Selenium JavaDoc which is available here:</p> <p><a href="http://selenium.googlecode.com/git/docs/api/java/index.html" rel="nofollow">http://selenium.googlecode.com/git/docs/api/java/index.html</a></p> <p>Example #1: Performing a sleep in the browser under test.</p> <pre><code>long start = System.currentTimeMillis(); ((JavascriptExecutor) driver).executeAsyncScript("window.setTimeout(arguments[arguments.length - 1], 500);"); System.out.println("Elapsed time: " + System.currentTimeMillis() - start); </code></pre> <p>Example #2: Synchronizing a test with an AJAX application</p> <pre><code>WebElement composeButton = driver.findElement(By.id("compose-button")); composeButton.click(); ((JavascriptExecutor) driver).executeAsyncScript( "var callback = arguments[arguments.length - 1];" + "mailClient.getComposeWindowWidget().onload(callback);"); driver.switchTo().frame("composeWidget"); driver.findElement(By.id("to")).sendKeys("bog@example.com"); </code></pre> <p>Example #3: Injecting a XMLHttpRequest and waiting for the result:</p> <pre><code>Object response = ((JavascriptExecutor) driver).executeAsyncScript( "var callback = arguments[arguments.length - 1];" + "var xhr = new XMLHttpRequest();" + "xhr.open('GET', '/resource/data.json', true);" + "xhr.onreadystatechange = function() {" + " if (xhr.readyState == 4) {" + " callback(xhr.responseText);" + " }" + "}" + "xhr.send();"); JSONObject json = new JSONObject((String) response); assertEquals("cheese", json.getString("food")); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload