How to Launch Firefox Browser in Selenium

Profile picture for user ksharma

To launch a firefox browser using selenium. First we need to download the gecko driver, also make sure firefox is installed on your system. 

Step 1: Open Firefox browser and Go to Firefox -> About Firefox and check your browser version or update to the latest version if you want.

Step 2: Open this link or you can search in google by typing "download geckodriver"

Step 3: Click Here to check if your browser is compatible with current Selenium version and driver. This will give you list of supported platforms. Your can also check the table below.

geckodriverSeleniumFirefox
  minmax
0.31.0≥ 3.11 (3.14 Python)91 ESRn/a
0.30.0≥ 3.11 (3.14 Python)78 ESR90
0.29.1≥ 3.11 (3.14 Python)6090
0.29.0≥ 3.11 (3.14 Python)6090
0.28.0≥ 3.11 (3.14 Python)6090
0.27.0≥ 3.11 (3.14 Python)6090
0.26.0≥ 3.11 (3.14 Python)6090
0.25.0≥ 3.11 (3.14 Python)5790
0.24.0≥ 3.11 (3.14 Python)5779
0.23.0≥ 3.11 (3.14 Python)5779
0.22.0≥ 3.11 (3.14 Python)5779
0.21.0≥ 3.11 (3.14 Python)5779
0.20.1≥ 3.55562
0.20.0≥ 3.55562
0.19.1≥ 3.55562
0.19.0≥ 3.55562
0.18.0≥ 3.45362
0.17.0≥ 3.45262

Here Firefox Extended Support Release (ESR) is an official version of Firefox developed for large organizations like universities and businesses that need to set up and maintain Firefox on a large scale.

Step 4: Here driver file is different for each operating system Windows exe will not work on Mac or Linux system. Unlike chrome here driver is different for 64 and 32 bit. Once you will click on link, download will start.

How to Launch Firefox Browser in Selenium

Step 5: Unzip and Paste downloaded file to drivers folder or directory of your choice.

Step 6: Now open your driver configuration file and paste following code. We will be executing this with Java runner using main class.

package com.pb.seltest.util;

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

public class AppTest 
{
	public static void main(String args[])
	{
		System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir") + "//drivers//geckodriver");
		
		WebDriver driver;
		driver = new FirefoxDriver();
		driver.get("http://www.automationpractice.com");
	}
}

In above code,

  • setProperty will set the system property to value webdriver.gecko.driver and the path is given to get the gecko driver.
  • Here WebDriver is the main interface which is extended by super most interface SearchContext.
  • new FirefoxDriver(), Here we are creating instance of FirefoxDriver, Firefox Driver is a class which also extends RemoteWebDriver class like ChromeDriver class do.
  • driver.get() is used to navigate particular URL(website) and wait till page load.