Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the gecko executable with Selenium

I'm using Firefox 47.0 with Selenium 2.53. Recently they have been a bug between Selenium and Firefox which make code not working. One of the solution is to use the Marionnette driver.

I followed the instruction of this site to use this new driver with a RemotWebDriver but I keep having the error :

WARN - Exception: Exception in thread "main" org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from ....

The code i've tried so far is very simple :

public class Test {     static WebDriver driver;     static Wait<WebDriver> wait;     public static void main(String[] args) throws MalformedURLException {         System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");         DesiredCapabilities cap = DesiredCapabilities.firefox();         cap.setCapability("marionette", true);         cap.setBrowserName("firefox");         driver = new RemoteWebDriver(new URL("http://192.168.117.135:5555/wd/hub"), cap);//true to enable the JS         wait = new WebDriverWait(driver, 3000);         final String url = "https://www.google.com/";          JavascriptExecutor js = (JavascriptExecutor) driver;          try {             driver.navigate().to(url);         } finally {             driver.close();         }     } } 

I'm sure that the path to the geckodriver.exe is right and i don't see where i did the mistake.

EDIT 1: I tried the following code :

public class Test {     static WebDriver driver;     static Wait<WebDriver> wait;     public static void main(String[] args) throws MalformedURLException {         System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");          driver = new MarionetteDriver();         wait = new WebDriverWait(driver, 3000);         final String url = "https://www.google.com/";          JavascriptExecutor js = (JavascriptExecutor) driver;          try {             driver.navigate().to(url);         } finally {             driver.close();         }     } } 

and it's working it seems that the problem come from the RemoteWebDriver and the gecko driver, any of you have news on it ?

like image 640
Robert Reynolds Avatar asked Jun 13 '16 09:06

Robert Reynolds


People also ask

How do I run GeckoDriver exe?

The path of the GeckoDriver executable file should be accessible to the FirefoxDriver, so as when the User creates an instance of the WebDriver using the FirefoxDriver, it should be able to find the path of the GeckoDriver executable file. It will lead to successful initialization.

What is Gecko driver 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.


2 Answers

Recently Selenium has launched Selenium 3 and if you are trying to use Firefox latest version then you have to use GeckoDriver:

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

You can check full documentation from here

like image 141
Mukesh otwani Avatar answered Sep 21 '22 01:09

Mukesh otwani


I am also facing the same issue and got the resolution after a day :

The exception is coming because System needs Geckodriver to run the Selenium test case. You can try this code under the main Method in Java

    System.setProperty("webdriver.gecko.driver","path of/geckodriver.exe");     DesiredCapabilities capabilities=DesiredCapabilities.firefox();     capabilities.setCapability("marionette", true);     WebDriver driver = new FirefoxDriver(capabilities); 

For more information You can go to this https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver link.

Please let me know if the issue doesn't get resolved.

like image 33
Purendra Agrawal Avatar answered Sep 22 '22 01:09

Purendra Agrawal