当前位置: 首页 > 知识库问答 >
问题:

线程“main”java中出现异常。lang.IllegalStateException[重复]

商璞
2023-03-14

我正在通过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/

共有1个答案

范云
2023-03-14

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

看看这个链接。

添加路径geckodriver.exeSystem.set属性。假设路径C:\Selenium\Firefox驱动程序\geckodriver.exe

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