Selenium WebDriver 3.0 需要注意的事项

首先,要使用WebDriver 3.0 的话 请使用JAVA 8(必要)

 

其次,由于W3C标准化以及各大浏览器厂商的积极跟进,自WebDriver 3.0 之后,Selenium不再提供默认的浏览器支持. 也就是说

如果你要使用Firefox, 就需要用到Mozilla自己的驱动实现: geckodriver ,这里是github下载地址 https://github.com/mozilla/geckodriver/releases

一个简单的例子

复制代码
1     public static void main(String[] args) {
2         System.setProperty("webdriver.gecko.driver", "d:\\geckodriver.exe");
3         DesiredCapabilities capabilities = DesiredCapabilities.firefox();
4         capabilities.setCapability("marionette", true);
5         WebDriver driver = new FirefoxDriver(capabilities);
6 
7     }
复制代码

 

如果你要使用Edge,就需要用到MS的WebDriver, 地址在这里:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

 

一个简单的例子

复制代码
1     public static void main(String[] args) {
2         System.setProperty("webdriver.edge.driver","d:\\MicrosoftWebDriver.exe"); //put actual location
3         WebDriver driver = new EdgeDriver();
4         driver.get("https://www.google.com");
5     }
复制代码

如果你要使用IE,现在只支持IE9以上版本(老版本或许也能使用), 使用方式和Webdriver 2.0 没有区别,你需要先下载InternetExplorerDriver.exe 地址在这里:https://pan.baidu.com/s/1i4Td8ax  注意64位或者32位

 

一个简单的例子

复制代码
 1     public static void main(String[] args) {
 2         System.setProperty("webdriver.ie.driver",
 3                 "../QACommon/src/main/resources/IEDriverServer.exe");
 4         DesiredCapabilities ieCapabilities = DesiredCapabilities
 5                 .internetExplorer();
 6         ieCapabilities.setCapability(
 7                 InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
 8                 true);
 9         WebDriver driver = new InternetExplorerDriver(ieCapabilities);
10     }
复制代码

 

如果你要使用Chrome, 和WebDriver 2.0 一样,你需要下载chromedriver驱动. 最新的地址在这里:http://chromedriver.storage.googleapis.com/index.html?path=2.25/

 

一个简单的例子

复制代码
1     public static void main(String[] args) {
2 
3         System.setProperty("webdriver.chrome.driver", "d:\\chromedriver.exe");
4         DesiredCapabilities capabilities = DesiredCapabilities.chrome();
5         WebDriver driver = new ChromeDriver(capabilities);
6         driver.get("http://www.google.com");
7     }
复制代码

 

猜你喜欢

转载自blog.csdn.net/u012111923/article/details/80703949