In System.setProperty(“webdriver.gecko.driver”, “<Path to your WebDriver>”), what is meant by “Path to your WebDriver”?

北战南征 提交于 2019-12-04 03:56:33

问题


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


回答1:


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!




回答2:


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.




回答3:


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();
    }

}



回答4:


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:


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.



来源:https://stackoverflow.com/questions/38873077/in-system-setpropertywebdriver-gecko-driver-path-to-your-webdriver-wha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!