java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45136914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:32:00  来源:igfitidea点击:

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property

javaseleniumgeckodrivergetproperty

提问by nsCelin

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/");

    }

}

Error

错误

I am getting the below exception with System.getProperty

我收到以下异常 System.getProperty

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/releasesat com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115) at 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.firefox.FirefoxDriver.(FirefoxDriver.java:137) at com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)

线程“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) 在 org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108) 在 org.openqa.selenium.firefox。 FirefoxDriver.(FirefoxDriver.java:137) 在 com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)

回答by Murthi

You have to use System.setProperty not the System.getProperty as follows.

您必须使用 System.setProperty 而不是 System.getProperty,如下所示。

System.setProperty("webdriver.gecko.driver",
                "C:\Selenium WebDriver\geckodriver\geckodriver-v0.17.0-win64\geckodriver.exe");

回答by Jainish Kapadia

I have noticed that you are using wrong syntax, to opening the browser.

我注意到您使用错误的语法来打开浏览器。

Instead of using System.getProperty, You have to use System.setPropertyas mentioned below.

而不是使用System.getProperty,您必须使用System.setProperty如下所述。

System.setProperty("webdriver.gecko.driver", "C:\Selenium WebDriver\geckodriver\geckodriver-v0.17.0-win64\geckodriver.exe");

For more details on this issue, refer this page.

有关此问题的更多详细信息,请参阅此页面