How to use gecko driver in Selenium

How to use gecko driver in Selenium

Firefox has changed its architecture and has started to use marionette and gecko driver. Does it affect how you work with Firefox using Selenium ? How to use gecko driver in Selenium 3.0 or even previous versions?

Selenium 3.0 was released recently. If you would like to know what’s changed in Selenium 3.0, you can refer to the following article by Techcanvass:

What’s new in Selenium 3.0

What is gecko driver ?

Gecko is a generic layout engine.  Mozilla has developed it as a separate project and it is used by many applications including Firefox browser or even SeaMonkey browser. Gecko engine reads the web content (written using HTML, CSS etc.) and then displays it on the screen or print it. From Firefox 48 onwards, gecko engine is used.

Gecko Driver and Selenium

Selenium 2.0 had a native support for Firefox browsers. That means, you never had to explicitly use any external driver in Selenium for Firefox. To understand this, let’s look at the code for Web driver instantiation for Firefox:

public static void main(String[] args)

{
  
  //Create FireFox Web Driver 
  WebDriver driver = new FirefoxDriver();
 
  //Launching the browser application
  driver.get(“http://www.yahoo.com”);

…..Do more

driver.close();

driver.quit();

}

As you see above, you can directly create an object of web driver for Firefox. This is because the support was included in Selenium 2.0 installation itself. However, for other browsers such as Chrome, IE or Edge, you needed to download the driver.

Let’s look at the code for Chrome Browser:

public static void main(String[] args)

{

String chromedriverpath = “C:\\Users\\master\\Desktop\\WIP\\Selenium-Jars\\ChromeDriver\\chromedriver.exe”;
 System.setProperty(“webdriver.chrome.driver”, chromedriverpath);

 // create a new instance of the Chrome driver
 WebDriver driver = new ChromeDriver();

 // Open the page we want to open
 driver.get(“http://www.yahoo.com”);

…..Do more

driver.close();

driver.quit();

}

This code will work only if you have downloaded the chrome driver from the Chrome website for Selenium. The same is true for other browsers as well.

So, what’s changed now ?

How to use gecko driver in Selenium?

Just like any other browser, you need to download the Firefox specific driver now. This Firefox driver is the Gecko driver. This driver is included in Selenium 3.0 by default, but if you are using the older version of Selenium, you need to explicitly download it.

Let’s see how do we write web driver instantiation code using Gecko driver:

public static void main(String[] args)

{

String Firefoxdriverpath = “D:\\automation\\Jar\\geckodriver-v0.10.0-win64\\geckodriver.exe”;

 System.setProperty(“webdriver.gecko.driver”, Firefoxdriverpath);

 // create a new instance of the Chrome driver
 WebDriver driver = new FirefoxDriver();

 // Open the page we want to open
 driver.get(“http://www.yahoo.com”);

…..Do more

driver.close();

driver.quit();

}

You can notice that, this code is similar to Chrome web driver instantiation code. There is no other difference. You need to download the Gecko Driver from Githhub deckdriver Release page.

If you have downloaded Selenium 3.0, then you don’t need to download Gecko Driver separately.

 

Leave a Reply

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