Why GeckoDriver is used in selenium?


The geckodriver can be used in 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 then launch the Firefox browser by instantiating an 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 −https://www.selenium.dev/downloads/ and move below the Browser section, there will be Firefox text present. Click on the Documentation link just below that.

  • All the geckodriver versions which are compatible with the corresponding Selenium versions shall be listed there.

Click on the geckodriver releases link.

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

  • After downloading the geckodriver, a zip file gets created. We need to extract that and save the geckodriver.exe file at any location.

Let us now 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>");

Example

Code Implementation

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LaunchFirefoxBrowser{
   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 = "https://www.tutorialspoint.com/index.htm";
      driver.get(url);
   }
}

Updated on: 26-Oct-2020

313 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements