尽管设置了正确的路径,但获得“必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径”

时间:2018-08-05 20:43:21

标签: java selenium-webdriver selenium-chromedriver

我的代码很简单:

 package Automation;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstTestCase {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver","/Users/Jagman/Downloads/chromedriver");
        WebDriver wd = new ChromeDriver();

        String url = ("https://www.google.com/");

        wd.get(url);

已经从selenium hq网站下载并添加了jar作为“ Java 3.13.0”。从同一网站下载Google Chrome Driver-2.29,并将其放在“ / Users / Jagman / Downloads / chromedriver”路径中。

运行上面的代码时,我收到错误消息“ java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738)".

尽管进行了正确的配置,但仍出现版本错误。请帮助我解决此问题。详细信息:操作系统:Mac。

1 个答案:

答案 0 :(得分:0)

在chromedriver路径中添加.exe:

System.setProperty("webdriver.chrome.driver","/Users/Jagman/Downloads/chromedriver.exe");