selenium3+Java 浏览器驱动的设置

1、selenium3之后就没有提供默认的浏览器驱动了,需要下载相应的驱动才能操作浏览器;

比如谷歌浏览器:

2、http://chromedriver.storage.googleapis.com/index.html 下载对应的驱动版本

2.1 解压放在磁盘的某个位置

2.2 添加环境变量

3、maven项目加入selenium的jar

     
            org.seleniumhq.selenium
            selenium-java
            3.141.59
        

4、测试demo

 public static void main(String[] args) {
        //System.setProperty("webdriver.chrome.driver","C:\\selenium_driver\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.baidu.com");
        String title = driver.getTitle();
        System.out.println(title);
        driver.close();
    }

5、注意事项

5.1、如果添加了驱动的环境变量且驱动的版本与你浏览器的版本一致,就不要这行代码了System.setProperty("webdriver.chrome.driver","C:\\selenium_driver\\chromedriver.exe");

5.2、java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property 

如果环境变量中没有找到驱动,就要用System.property来手动指定驱动的位置,就是上面注释的那行代码

你可能感兴趣的:(软件测试,selenium3,selenium)