In System.setProperty(“webdriver.gecko.driver”, “<

2020-04-07 05:49发布

I have this exception since I upgraded to 3.0 beta with Firefox.

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property

5条回答
老娘就宠你
2楼-- · 2020-04-07 06:05

We use System.setProperty to provide the path of chromedriver/iedriver etc. Below is the declaration of java.lang.System.setProperty() method:

public static String setProperty(String key, String value)

key : Name of the system property

value: Value of the system property

e.g. System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");

webdriver.chrome.driver : Chrome Driver (Name of system property) src/test/resources/chromedriver.exe : Path of chromedriver (value of system property)

Usually, we encounter IllegalArgumentException when key is empty.

查看更多
我想做一个坏孩纸
3楼-- · 2020-04-07 06:06

It seems now we need to manually download and set path to the driver executable for Mozilla Firefox also just like chromedriver.

Following is what you need to do:-

  1. Go to http://docs.seleniumhq.org/download/
  2. Scroll down to "Third Party Drivers, Bindings, and Plugins" section on downloads page
  3. Click on Mozilla GeckoDriver and download(zip) latest version v0.10.0 for your operating system.
  4. Extract on your desired location i.e. c:\GeckoDriver\geckodriver.exe

Now you need to set system property and write following lines to initialize FireFoxDriver object:-

System.setProperty("webdriver.gecko.driver", "C:\GeckoDriver\geckodriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("http://seleniumhq.com");

Thats it!

查看更多
Luminary・发光体
4楼-- · 2020-04-07 06:08

public class WaitTestCase { WebDriver driver;

@Test ()    
public void TC_Wait(){

System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");

driver = new FirefoxDriver();


        driver.get("http:\\yahoo.com");

        driver.quit();
}

}

查看更多
老娘就宠你
5楼-- · 2020-04-07 06:17

Try below code in JAVA, and its working fine me

  1. need to updated selenium and selenium drivers for java

  2. updated firefox, firefox driver

in below code "C:\\Drivers\\geckodriver.exe" is path of your webdriver

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstTestCase {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //WebDriver driver =new FirefoxDriver();

        System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("https://www.syncfusion.com/");
         System.out.println("Successfully opened the website www.Syncfusion.com"); 
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         driver.quit();
    }

}
查看更多
不美不萌又怎样
6楼-- · 2020-04-07 06:18
System.setProperty("webdriver.gecko.driver","C://Program Files (x86)//geckodriver-v0.11.1-win64//geckodriver.exe");
String testurl = "http://www.seleniumhq.com";
WebDriver driver = new FirefoxDriver();
driver.get(testurl);

Normally this happens when the FF version is above 45 and thats when we download gecko driver (https://github.com/mozilla/geckodriver/releases). After this unzip the contents of the folder and drag and drop the exe file of gecko driver to this folder (src/main/resources) if you have created a maven project.

查看更多
登录 后发表回答