Selenium
1. selenium 操作 checkbox 和 radio 参考How to Select CheckBox and Radio Button in Selenium WebDriver
selenium 操作 checkbox 和 radio 都是用click()方法
2.selenium webdriver 执行 javascript
参考 HOW TO EXECUTE JAVASCRIPT IN SELENIUM 参考 webdriver js点击无法点击的元素
java:
String title = ((JavascriptExecutor) driver).executeScript("return document.title;").toString();
python
title = driver.execute_script("return document.title;")
3.selenium + IE 浏览器 IE Driver Server
IEDriverServer的版本号和Selenium的版本号一定要保持一致 下载IEDriver
4.selenium + IE 浏览器可能报错 zoom
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 125%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.16 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'AAAAAA', ip: '123.123.123.123', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
解决办法
方法1.打开IE----setting----把zoom调成100%
方法2. java 参考 Selenium: Unexpected error launching IE. Browser zoom level was set to 122%. It should be set to 100%
InternetExplorerOptions capabilities = new InternetExplorerOptions();
capabilities.ignoreZoomSettings();
driver = new InternetExplorerDriver(capabilities);
5.IE浏览器输入英文和数字会特别慢
selenium自动化测试中,有些IE浏览器输入英文和数字会特别慢,大大降低了自动化测试的执行速度。此问题一般出现在64位Windows系统中。
解决:将"IEDriverServer.exe"从64位版本变为32位版本。
6.selenium + IE 浏览器 ,click()方法不起作用,可以尝试
java
driver.findElement(By.id("username")).sendKeys(Keys.ENTER);
7.selenium + IE 浏览器 ,click()方法不起作用,可以尝试
java
InternetExplorerDriver driver = new InternetExplorerDriver();
WebElement element= driver.findElement(By.id("username"));
// 方法1:Perform Click on element using JavascriptExecutor
// //auguments[0]代表element
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", element);
8.selenium + IE 浏览器 ,<a>元素 click()方法不起作用,可以尝试
java
InternetExplorerDriver driver = new InternetExplorerDriver();
WebElement element= driver.findElement(By.id("username"));
String url = element.getAttribute("href"); // 获取目标元素的url
driver.get(url);
9.selenium + IE 浏览器 ,<a>元素 click()方法不起作用,可以尝试
java
InternetExplorerDriver driver = new InternetExplorerDriver();
WebElement element= driver.findElement(By.id("username"));
String url = element.getAttribute("href"); // 获取目标元素的url
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.open('" + url + "')"); // window.open()点击目标元素
10.selenium + Edge 浏览器:
下载和Edge浏览器 相同版本的WebDriver 下载 Edge-WebDriver
How to launch Edge browser in Selenium
11.selenium + Edge 浏览器:
报错:org.openqa.selenium.WebDriverException: Unable to parse remote response: Unknown error
因为:Edge only allows one instance to be running for Web Driver testing. 同时只能打开一个浏览器实例