Execute Selenium Test on Firefox browser using GeckoDriver

GeckoDriver server is required in selenium 3, if you want to execute a script on Firefox browser. It can be downloaded from here.

GeckoDriver

Geckodriver is an implementation of WebDriver.

You can refer following GeckDriver documentation for complete details – Click Here.

Why there is a need of GeckoDriver ?

After Firefox Version 47, Firefox browser doesn’t allow any 3rd party tool to interact directly with it. Hence in order to interact with it, we need a proxy called GeckoDriver. In Simple terms, Selenium will send the request to GeckDriver using W3C WebDriver Protocol and then GeckoDriver will read the commands and translate them into Marionette Protocol and forwards the request to Firefox Browser. Browser will read the commands in the form of Marionette protocol and execute them.

1

Command to setup Gecko Driver path in your selenium code

System.setProperty("webdriver.gecko.driver", "C:/gridsetup/geckodriver.exe");

Sample Script

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirefoxSampleScript {

	public static void main(String[] s) throws Exception {
		// Set Gecko driver path
		System.setProperty("webdriver.gecko.driver", "C:/gridsetup/geckodriver.exe");

		// Initialize Firefox Driver
		WebDriver driver = new FirefoxDriver();

		// Launch Google on Firefox Browser
		driver.get("http://www.google.com/");

		// Wait for 2 seconds
		Thread.sleep(2000);

		// Close Browser
		driver.close();

	}

}

If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *