简体   繁体   English

线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置

[英]Exception in thread "main" java.lang.IllegalStateException:The path to the driver executable must be set by the : system property

Exception in thread "main" 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:199)  
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)  
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)  
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)   at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)   
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)    
at practise_locators.DatePicker.main(DatePicker.java:11)

Here is my code:这是我的代码:

package practise_locators;

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

public class DatePicker {

    public static void main(String[] args){
        WebDriver driver = new ChromeDriver();
        System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
        driver.get("https://www.google.com");
    }

}

The error says it all :错误说明了一切:

Exception in thread "main" 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:199) 

The following phrases from the error implies that there is an error in the line containing webdriver.chrome.driver错误中的以下短语暗示包含webdriver.chrome.driver的行中存在错误

The error can be either of the following :错误可能是以下之一:

  • Error in the System Class Method setProperty() (including sequence) : 系统类方法setProperty()中的错误(包括序列):

     System.setProperty()

    This line should be the very first line in your script.此行应该是脚本中的第一行

  • Error in the specified Key :指定中的错误:

     "WebDriver.Chrome.driver"
  • Error in the Value field :字段中的错误:

     "E:\\chromedriver.exe"

    You have to pass the absolute path of the WebDriver through either of the following options :您必须通过以下任一选项传递WebDriver的绝对路径:

    • Escaping the back slash ( \\ ) eg "C:\\path\\to\\chromedriver.exe"转义反斜杠 ( \\ ) 例如"C:\\path\\to\\chromedriver.exe"
    • Single forward slash ( / ) eg "C:/path/to/chromedriver.exe"单正斜杠 ( / ) 例如"C:/path/to/chromedriver.exe"

Your code seems to be having two issues as follows :您的代码似乎有以下两个问题:

  • First issue is in specifying the Key which instead of "WebDriver.Chrome.driver" should have been "webdriver.chrome.driver" as follows :第一个问题是指定密钥而不是"WebDriver.Chrome.driver"应该是"webdriver.chrome.driver" ,如下所示:

     System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
  • Second issue is in the sequence of mentioning the Key "webDriver.chrome.driver" in your program which should be before WebDriver driver = new ChromeDriver();第二个问题是在你的程序中提到"webDriver.chrome.driver"的顺序,它应该在WebDriver driver = new ChromeDriver();之前。 as follows :如下 :

     System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.google.com");

for me the issue still exist after this: if (config.getProperty("browser").equals("chrome")) {对我来说,此后问题仍然存在: if (config.getProperty("browser").equals("chrome")) {

            System.getProperty("webdriver.chrome.driver",
                    "C:\\Selenium\\LearningProject\\DataDrivenFramework\\src\\test\\resources\\executables\\chromedriver.exe");

            driver = new ChromeDriver();

I have seen many people are using wrong sequence.我见过很多人使用错误的顺序。 the sequence should be.顺序应该是。

  1. First set the property and then launch the browser首先设置属性,然后启动浏览器

System.setProperty("webdriver.chrome.driver", "F:/chrome/chromedriver.exe"); System.setProperty("webdriver.chrome.driver", "F:/chrome/chromedriver.exe"); WebDriver driver = new ChromeDriver(); WebDriver driver = new ChromeDriver();

      driver.navigate().to("https://www.google.com");

Download the chromedriver version corresponding to the chrome version in your system from https://chromedriver.chromium.org/downloads .https://chromedriver.chromium.org/downloads下载对应你系统 chrome 版本的 chromedriver 版本。 Unzip the file and run the below code in the IDE.解压缩文件并在 IDE 中运行以下代码。

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

public class Selintroduction {公共 class Selintroduction {

public static void main(String[] args) {

    //Invoking browser
System.setProperty("webdriver.chrome.driver","C:\\Users\\HP\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

}

} }

(Path would depend on your file location in the PC.) (路径将取决于您的文件在 PC 中的位置。)

I was facing the same error when my code was like so:当我的代码是这样时,我遇到了同样的错误:

System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32.exe");

It works after adding "chromedriver" before ".exe" like so:它在".exe"之前添加"chromedriver"后工作,如下所示:

System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32\\chromedriver.exe");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统设置 - Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system Geckodriver 错误:线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 - Geckodriver Error: Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by java.lang.IllegalStateException:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径; - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置 - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property Selenium:-java.lang.IllegalStateException: 驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置 - Selenium:-java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置 - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置; (驱动程序.get) - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; (driver.get) TestNG Selenium Java — java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置 - TestNG Selenium Java — java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property Selenium Java-java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置 - Selenium Java - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property 线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件是一个目录 - Exception in thread “main” java.lang.IllegalStateException: The driver executable is a directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM