Skip to main content

How to Launch Firefox Browser in Selenium

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.

geckodriver Selenium Firefox
    min max
0.31.0 ≥ 3.11 (3.14 Python) 91 ESR n/a
0.30.0 ≥ 3.11 (3.14 Python) 78 ESR 90
0.29.1 ≥ 3.11 (3.14 Python) 60 90
0.29.0 ≥ 3.11 (3.14 Python) 60 90
0.28.0 ≥ 3.11 (3.14 Python) 60 90
0.27.0 ≥ 3.11 (3.14 Python) 60 90
0.26.0 ≥ 3.11 (3.14 Python) 60 90
0.25.0 ≥ 3.11 (3.14 Python) 57 90
0.24.0 ≥ 3.11 (3.14 Python) 57 79
0.23.0 ≥ 3.11 (3.14 Python) 57 79
0.22.0 ≥ 3.11 (3.14 Python) 57 79
0.21.0 ≥ 3.11 (3.14 Python) 57 79
0.20.1 ≥ 3.5 55 62
0.20.0 ≥ 3.5 55 62
0.19.1 ≥ 3.5 55 62
0.19.0 ≥ 3.5 55 62
0.18.0 ≥ 3.4 53 62
0.17.0 ≥ 3.4 52 62

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.

Video Tutorial: How to Open Firefox Browser in Selenium

Submitted by ksharma on September 26, 2020

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.