当前位置: 首页 > 知识库问答 >
问题:

java.lang.IllegalStateException:驱动程序可执行文件的路径必须由WebDriver.Chrome.driver系统属性设置

干京
2023-03-14
package Basics;

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

public class invokegoogle {

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

    System.setProperty("Webdriver.chrome.driver", "C:\\Users\\sravani\\Desktop.exe");
    WebDriver driver=new ChromeDriver();
    driver.get("http://qaclickacademy.com");

    }

}

获取以下错误:

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:754)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
    at Basics.invokegoogle.main(invokegoogle.java:12)

任何帮助都是非常感谢的。提前致谢

共有1个答案

魏兴邦
2023-03-14

假设Chromedriver.exe存储在桌面上,则需要进行以下几项更改:

>

  • 您需要在webdriver.chrome.driver中用小写w替换大写w
  • 当您在windows系统上时,假定Chromedriver.exe放置在您的桌面中,您需要在WebDriver的绝对路径中附加WebDriver变体名称和扩展名。
  • 实际上,代码行将为:

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

    注意:webdriver.chrome.driver需要以小写字母开头。

  •  类似资料: