package com.merchantPlatform;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MerchantPlatformTest {
public static void main(String[] args) {
System.getProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
// Initialize WebDriver
WebDriver driver = new FirefoxDriver(capabilities);
/* This works fine for versions lesser than Selenium 3. For Selenium 3 and higher, it will throw java.lang.IllegalStateException */
// Maximize Window
driver.manage().window().maximize();
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Navigate to MerchantPlatform URL
driver.get("http://localhost:52939/");
}
}
錯誤java.lang.IllegalStateException:到驅動程序可執行文件的路徑必須由webdriver.gecko.driver系統屬性設置
我與System.getProperty
異常,提示以下異常在線程「main」java.lang.IllegalStateException中:驅動程序可執行文件的路徑 必須由webdriver.gecko.driver 系統屬性設置;欲瞭解更多信息,請參閱 https://github.com/mozilla/geckodriver。最新版本可以是 ,從https://github.com/mozilla/geckodriver/releases 下載,位於com.google.common.base.Preconditions.checkState(Preconditions.java:738) ,位於org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124 ) 在org.openqa.selenium.firefox.GeckoDriverService.access $ 100(GeckoDriverService.java:41) 在org.openqa.selenium.firefox.GeckoDriverService $ Builder.findDefaultExecutable(GeckoDriverService.java:115) 在org.openqa。 selenium.remote.service.DriverService $ Builder.build(DriverService.java:330) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207) at org.openqa.selenium.firefox.FirefoxDriver。 (FirefoxDriver.java:108) at org.openqa.selenium.firefo x.FirefoxDriver(FirefoxDriver.java:137) 在com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)
刪除webdrivers的目錄名稱中的空格,並嘗試 –