Java.lang.IllegalStateException: The path to the driver executable must be set using the webdriver.gecko.driver property

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

    }

}

      

Mistake

I am getting the following exception: System.getProperty

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set to the webdriver.gecko.driver system property; see https://github.com/mozilla/geckodriver for more information . The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases      at 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.GeckoDvice .access $ 100 (GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService $ Builder.findDefaultExecutable (GeckoDriverService.java:115) at org.openqa.selenium.Driverte.service java: 330) to org.openqa.selenium.firefox.FirefoxDriver.toExecutor (FirefoxDriver.java:207) to 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)

+3


source to share


2 answers


You should be using System.setProperty and not System.getProperty as shown below.



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

      

+5


source


I noticed that you are using the wrong syntax to open the browser.

Instead of using System.getProperty

, you should use System.setProperty

as below.



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

      

For more details on this issue see page .

+1


source







All Articles