WebDriver?????JavaScript
???????????? ???????[ 2015/2/15 16:03:24 ] ????????WebDriver ?????????? JavaScript
??????????????????? 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???????????????????б???????????????κ?????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11