??????????????????? JavascriptExecutor js = (JavascriptExecutor) driver; ??JavascriptExector????
????????????executeScript()?????????JS??
????????
????1. ??Google???
????2. ???JS???????е?title  --- document.title
????3. ????????????????? ----var links = document.getElementsByTagName('A'); return links.length
???????????????
package com.example.tests;
import static org.junit.Assert.*;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class test {
@Test
public void testJavaScriptCalls() {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com.hk");
JavascriptExecutor js = (JavascriptExecutor) driver;
String title = (String) js.executeScript("return document.title");
assertEquals("Google"?? title);
long links = (Long) js.executeScript("var links = "
+ "document.getElementsByTagName('A'); "
+ "return links.length");
assertEquals(32?? links);
driver.close();
}
}
??????javaScript?????з???????????????????return??????????????????????????????executeScript() ?????????????????С???????????Double???????С??????????Long?????????????????Boolean???????????????HTML?????????? WebElement??????????????????String???????????????????б???????????????κ?????????