
参考地址:http://www.cnblogs.com/fnng/p/5932224.html
https://github.com/mozilla/geckodriver
【火狐浏览器】
火狐浏览器的驱动下载地址:https://github.com/mozilla/geckodriver/releases
要求火狐浏览器版本:Support is best in Firefox 52.0.3 and onwards,最好是52及之后的版本
要求selenium版本:Selenium3.0及+
新建一个文件夹,如d:\seleniumdriver,将geckodriver.exe放置到该文件夹,再将d:\seleniumdriver配置到系统变量的Path里面
package ant_junit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestFirefox {
public static void main(String[] args) {
//如果火狐不是在默认目录下,需要这样设置一下火狐的路径,不然会报找不到火狐的错误
System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver dr = new FirefoxDriver();
dr.get("http://www.baidu.com");
dr.findElement(By.id("kw")).sendKeys("test");
dr.quit();
}
}
【谷歌浏览器】
谷歌浏览器的驱动下载地址:https://code.google.com/p/chromedriver/downloads/list,但是国内有时访问不了,可以去网上其他地址搜索下一个
要求谷歌浏览器版本:一般最新的都支持
新建一个文件夹,如d:\seleniumdriver,将chromedriver.exe放置到该文件夹,再将d:\seleniumdriver配置到系统变量的Path里面
package ant_junit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChromeDriver {
public static void main(String[] args) {
//一般谷歌的安装都在默认目录下,当将chromedriver.exe配置到系统Path后,则可直接启动
WebDriver dr = new ChromeDriver();
dr.get("http://www.baidu.com");
dr.findElement(By.id("kw")).sendKeys("test");
dr.quit();
}
}
备注:
本人机器上测试成功的JDK版本:1.8
Selenium服务器版本:selenium-server-standalone-3.4.0.jar