0

我是 selenium web 驱动程序的新手,在编译脚本以在 MACOS 中打开新浏览器时。我收到此错误:

exception in thread "main" java.lang.IllegalStateException: 
The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
  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.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37)
  at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95)
  at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
  at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)
  at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:247)
  at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:242)
  at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:238)
  at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
  at NewPackage.NewClass.main(NewClass.java:93)

请帮忙解决这个问题......

4

1 回答 1

0
System.setProperty("webdriver.gecko.driver","path of/geckodriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);

正如 sudharsan 所建议的,我使用了上面的代码,因为我在 MAcos 中工作,它开始给我更多的错误,上面代码的细微变化是我们在 MAC 中指定路径时不需要 .exe 扩展名......

 System.setProperty("`webdriver.gecko.driver","path of/geckodriver");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);

这给了我正确的输出。

于 2016-10-20T15:29:22.363 回答