gpt4 book ai didi

java - 在 Java Eclipse 中使用 Selenium WebDriver 启动 Chrome 时出错 - 线程 "main"中出现异常

转载 作者:行者123 更新时间:2023-12-01 19:41:47 29 4
gpt4 key购买 nike

当我尝试在 Java Eclipse 中使用 Selenium WebDriver 启动 Chrome 时,收到此错误消息。 (Java Eclipse 在 U 盘中)Java代码-封装 SeleniumSessions;

import java.util.concurrent.TimeUnit;

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

public class WebDriverBasics {

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

// chrome browser
System.setProperty("webdriver.gecko.driver", "C:\\Users\\waychal\\Downloads\\geckodriver.exe");

WebDriver driver = new ChromeDriver(); // launch Chrome browser
driver.get("https://www.google.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:847)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at SeleniumSessions.WebDriverBasics.main(WebDriverBasics.java:15)

最佳答案

异常要求提供 Chrome 驱动程序的路径

The path to the driver executable must be set by the webdriver.chrome.driver system property

您正在为 gecko 驱动程序进行设置

 System.setProperty("webdriver.gecko.driver", "C:\\Users\\Downloads\\geckodriver.exe"); 

我不太清楚,但我建议您使用 Chromedriver 并设置正确的属性。

关于java - 在 Java Eclipse 中使用 Selenium WebDriver 启动 Chrome 时出错 - 线程 "main"中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55140269/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com