Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use geckodriver in selenium webdriver 3.0 beta?

How can I use geckodriver for selenium webdriver 3.0 beta release. When I instantiate firefox like:

WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "//lib//geckodriver");
driver.get("/");

I get error:

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.

like image 265
Priyanshu Shekhar Avatar asked Aug 01 '16 06:08

Priyanshu Shekhar


People also ask

How do you write GeckoDriver in Selenium?

Steps to Add a Path in System's PATH Environmental Variable Click on the Environment Variables button. From System Variables select PATH. Click on the Edit button. Paste the path of the GeckoDriver file.

What is the use of GeckoDriver in Selenium?

GeckoDriver serves as a proxy between WebDriver enabled clients and the Firefox browser. In other words, GeckoDriver is a link between Selenium tests and the Firefox browser. It is a proxy for using W3C WebDriver-compatible clients that lets them interact with Gecko-based browsers.

How do I open Firefox browser with GeckoDriver in Selenium?

Step 1: Navigate to the official Selenium website. Under third-party drivers, one will find all the drivers. Just click on the Mozilla GeckoDriver documentation as shown below. Now, it will navigate to the GeckoDriver downloads link, where one can download the suitable driver based on the OS as it is platform agnostic.


3 Answers

Got the solution:

System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
like image 74
Priyanshu Shekhar Avatar answered Oct 21 '22 08:10

Priyanshu Shekhar


I have used the code as below, without setting the DesiredCapabilities and it works fine, without any issues

System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
WebDriver driver = new FirefoxDriver();
like image 43
Anish Pillai Avatar answered Oct 21 '22 09:10

Anish Pillai


Example of how to define Firefox driver in selenium 3.x series will be:

WebDriver driver;
System.setProperty("webdriver.gecko.driver", "G:\\Drivers\\geckodriver.exe");
driver = new FirefoxDriver();

Remember this (Selenium 3.x) will also require Jave 8+ versions.

like image 42
Ankit Bhatti Avatar answered Oct 21 '22 08:10

Ankit Bhatti