How to use the gecko executable with Selenium?

We can use gecko executable driver with Selenium webdriver. For the Mozilla version above 47, the geckodriver is used due to the presence of Marionette, which is the driver for automation in Mozilla. We can launch the Firefox by instantiating the object of FirefoxDriver class with the help of the below statement.

WebDriver driver=new FirefoxDriver();

Next we have to download the geckodriver and configure it to our project by following the below step by step processes −

  • Navigate to the link − and move below the Browser text, there is a Firefox section available. Click on the Documentation link just below that.

  • All the geckodriver versions which are compatible with the corresponding Selenium versions shall be listed. Click on the geckodriver releases link.

  • Next we have to download the geckodriver as per the operating system.

  • After downloading the geckodriver as per the system configuration, a zip file gets created. We need to extract that and put the geckodriver.exe file at any location.

Let us discuss how to configure geckodriver with System properties within the Selenium code −

  • Add the System.setProperty method in the code which takes the browser type and the path of the geckodriver executable path as parameters.

System.setProperty("webdriver.gecko.driver","<geckodriver path>");


Code Implementation.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LaunchFirefox{
   public static void main(String[] args) {
      // creating object of FirefoxDriver
      WebDriver driver = new FirefoxDriver();
      // to configure the path of the geckodriver.exe
      System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
      String url = "";

Updated on: 26-Oct-2020


Kickstart Your Career

Get certified by completing the course

Get Started