尝试使用selenium Web Driver加载Firefox时,在Java代码中出错

时间:2018-02-09 06:15:11

标签: eclipse selenium-webdriver geckodriver

即使我为gecko驱动程序设置了正确的路径,我也会遇到错误。

以下例外情况:

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\geckodriver-v0.19.1-win64.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
at com.package1.Test.main(Test.java:14)

1 个答案:

答案 0 :(得分:0)

错误说明了一切:

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\geckodriver-v0.19.1-win64.exe

这意味着 GeckoDriver 二进制文件不存在为C:\Selenium\geckodriver-v0.19.1-win64.exe

解决方案

使用 Selenium 3.x 时,需要从this site下载zip / tar格式的 GeckoDriver 二进制文件,提取二进制文件并将其存储在任何位置在你的系统内。然后在System.setProperty()行内的程序中,您需要提及 GeckoDriver 二进制文件的绝对路径,如下所示:

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