In last post, we have learnt how to launch Chrome driver through selenium. In this post we will learn:

  1. How to launch Firefox browser through Selenium 3.
  2. Open a URL in browser.
  3. Close the browser.

Selenium 3 has been launched. In selenium 2, it was very easy to launch Firefox browser as Selenium 2 had native implementation of Firefox browser. As we know that Selenium provides a driver class for each browser. So to open Firefox browser, we just need to create an object of FirefoxDriver class as below:

FirefoxDriver driver= new FirefoxDriver();

Note: “driver” is an object or reference variable of class FirefoxDriver. You can name it anything you wish. Someone asked me that is “driver” fixed. So, I am putting this point here.

Selenium 3 has not any native implementation of Firefox browser. Marionette is the next generation of FirefoxDriver. Marionette is an automation driver for Mozilla’s Gecko engine. Gecko is the proprietary web browser engine design and developed by Mozilla. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox. So, to support Selenium webdriver, Gecko has released Geckodriver which is a proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers.

How to launch Firefox browser in SELENIUM 3:

Step 1: Download the latest geckodriver from here as per your system configuration. I will download for windows 64 bits.

Step 2: Extract it and so that you will get geckodriver.exe.

Step 3: Just set the system property using System class and setProperty method of it as we did for chrome browser in previous post.

Java code for opening Firefox browser is as below:


import org.openqa.selenium.firefox.FirefoxDriver;

public class LaunchFirefoxBrowser {

public static void main(String[] args) {

//setting path of geckodriver
System.setProperty("webdriver.gecko.driver", "D:/Organised/Selenium_Frameworks/DataDrivenFramework/exefiles/geckodriver.exe");
// Launching firefox browser
FirefoxDriver FDriver= new FirefoxDriver();
// Opening a URL
FDriver.get("https://www.google.com");
// Closing the browser
FDriver.quit();
}
}

Note:

There are some issues with geckodriver. Sometimes we will face:

  1. Browser remains minimized after opening.
  2. quit() will give exception.
  3. Syncing issue between versions of geckodriver and Firefox.

That’s it for this post. I hope, you must have get above concepts. Feel free to ask any doubt if you have or any suggestion for me.

#HappyLearning

5 thoughts on “Launch of Firefox Browser through Selenium 3:

  1. I have observed the quit option is not working several times, how can we fix the quit function issue for Firefox driver?

    1. Hi Uma,

      It is quite a problem in firefox. Sometimes close also does not work. You can use javascript way to close a window. Command is “window.close()”.
      Thanks
      Amod

  2. @Amod…Thank you for your useful post
    Here are some doubts,
    Is it useful if we start using selenium 3 instead other lesser versions??
    Is is necessary to adopt selenium 3??

Leave a Reply