selenium - 通过设置正确的路径获取 "The path to the driver executable must be set by the webdriver.chrome.driver system property"

标签 selenium selenium-webdriver selenium-chromedriver

我的代码很简单
代码:

WebDriver wd =new ChromeDriver();
  System.setProperty("webdriver.chrome.driver",
                     "D:\\List_of_Jar\\chromedriver.exe");    
       String baseUrl = "https://www.google.com";wd.get(baseUrl);
已从 selenium hq 站点下载并添加 jar 为“Java-3.4.0”。
从同一网站下载 Google Chrome Driver-2.29 并将其放置在“D:\List_of_Jar”路径中。
当我运行上面的代码时,我得到一个错误
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)
尽管进行了正确的配置,但出现版本错误。所以请帮我解决这个问题。
细节:
  • 操作系统:Windows XP。
  • Java:JDK1.8 和 JRE1.8。
  • Selenium :版本 3.4
  • 最佳答案

    我完全同意 Murthi,但更好的是设置驱动程序的相对路径,而不是绝对路径。

    相对路径如下:

    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
    

    Abosulte:是您 PC 中驱动程序的路径。
    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    

    为什么?
    在您的项目中包含驱动程序是一个很好的做法,而不仅仅是在您的计算机中。只需找到或创建文件夹 f.e.资源,在资源内部创建名为 f.e. 的文件夹驱动程序并在那里导入您的驱动程序/驱动程序 exe 文件。

    关于selenium - 通过设置正确的路径获取 "The path to the driver executable must be set by the webdriver.chrome.driver system property",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44476647/

    相关文章:

    java - 从 Selenium 调用 Tor 的 WebDriver

    Javascript promise 不等待异步函数完成

    java - 如何制作WebDriver项目的Java可执行Jar文件

    java - 如何在 selenium webdriver 中使用 css 检查按钮是否被禁用

    java - 为什么 xpath 什么都不做?

    python - unDetected_chromedriver 运行缓慢,有建议吗?

    python - 没有这样的元素 : Unable to locate element using chromedriver and Selenium in production environment

    selenium - 如何使用 Selenium Webdriver 自动化验证码?

    java - 循环下拉网络驱动程序

    ruby - 无法找到 chromedriver 可执行文件