【问题标题】:Exception in thread "main" java.lang.IllegalStateException [duplicate]线程“主”java.lang.IllegalStateException中的异常[重复]
【发布时间】:2017-01-11 14:08:40
【问题描述】:

我正在学习 selenium 的自动化测试教程,并且正在用 java 语言编写我的第一个脚本,并且在 Eclipse 的“控制台”中收到了该消息。

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$100(GeckoDriverService.java:38)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:220)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:215)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
at automationFramework.FirstTestCase.main(FirstTestCase.java:12)

我的代码:

package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {

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

    // Create a new instance of the Firefox driver
    WebDriver driver = new FirefoxDriver();

    //Launch the Online Store Website
    driver.get("http://www.store.demoqa.com");

    // Print a Log In message to the screen
    System.out.println("Successfully opened the website www.Store.Demoqa.com");

    //Wait for 5 Sec
    Thread.sleep(5);

    // Close the driver
    driver.quit();
}

}

教程链接: http://toolsqa.wpengine.com/selenium-webdriver/first-test-case/

【问题讨论】:

    标签: java eclipse selenium testing automation


    【解决方案1】:

    这是因为 Selenium 3 使用单独的驱动程序与 Firefox 浏览器交互。

    查看this link

    geckodriver.exe的路径加上System.setProperty。假设路径C:\Selenium\Firefox driver\geckodriver.exe

    System.setProperty("webdriver.gecko.driver","C:\Selenium\Firefox driver\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    

    【讨论】:

      猜你喜欢
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 2021-02-10
      相关资源
      最近更新 更多