在线程" main"中获取错误xception java.lang.IllegalStateException

时间:2016-10-19 15:54:13

标签: java selenium selenium-webdriver geckodriver

我是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)

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

1 个答案:

答案 0 :(得分: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扩展... < / p>

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

这给了我正确的输出。