Skip to main content

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 this link or you can search in google by typing "download geckodriver"

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

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.27.0 ≥ 3.11 (3.14 Python) 60 n/a
0.26.0 ≥ 3.11 (3.14 Python) 60 n/a
0.25.0 ≥ 3.11 (3.14 Python) 57 n/a
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

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.

download geckodriver

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. Since we have not introduced TestNG or JUnit yet, 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

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.