2016-09-03 57 views
-2

我正在學習selenium的自動化測試教程,並且正在用java語言編寫我的第一個腳本,並在Eclipse的「Console」中獲得了該消息。線程「main」中的異常java.lang.IllegalStateException

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

這是因爲硒3使用一個單獨的驅動器與Firefox瀏覽器進行交互。

結帳this link

添加geckodriver.exeSystem.setProperty的路徑。假設路徑C:\Selenium\Firefox driver\geckodriver.exe

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

非常感謝你 –

相關問題