Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

How To Launch Firefox Browser in Selenium WebDriver – Java

Posted on 03/16/2025 By admin

Selenium automates a browser. There are multiple browsers supported by Selenium WebDriver. Major browsers are – Google Chrome, Mozilla Firefox, Microsoft Internet Explorer, Microsoft Edge, Opera, and Safari. In this post, we will learn to “Launch a firefox browser in Selenium WebDriver 3 and 4“.

First, check if you have firefox browser installed in your system. If it is installed then jump to the next step otherwise install the firefox browser from here. Installation is just like any other software installation. Click on the installation file and Next Next Next……

Since we will use Java binding of Selenium WebDriver to launch a firefox browser, please set up a Selenium Java project as discussed here.

Selenium WebDriver provides corresponding classes for browsers. For example:- For Chrome -> ChromeDriver, For Firefox -> FirefoxDriver. To launch any browser through Selenium WebDriver we just need to create an object of their corresponding class.

package BasicSeleniumConcepts;

import org.openqa.selenium.firefox.FirefoxDriver;

public class LaunchFirefoxBrowser {
        
        public static void main(String[] args) {
                
                FirefoxDriver firefoxDriver = new FirefoxDriver();
                firefoxDriver.get("https://www.google.com/");
        }

}

Run above program and observe the output.

We were expecting that a firefox browser should have launched but we got an exception IllegalStateException and states that “The path to the driver executable must be set by the webdriver.gecko.driver system property“.

Selenium WebDriver can not communicate with a browser directly. We need an intimidatory executable agent between Selenium WebDriver and the actual browser. These intimidatory are provided by third parties. For firefox, we need a geckodriver as an interface between Selenium WebDriver and a real firefox browser.

There is a critical part that for each version of the Firefox browser, you may have different geckodriver executable version. Many times you may face issues when Selenium will not be able to create a WebDriver session and maximum time reason is an incompatibility of Firefox browser version and geckodriver version.

I will advised you to download the latest firefox browser and geckodriver always. If you are using an older version of Firefox due to some restrictions always read release notes to know which geckdriver version will support your current version of firefox browser.

I have installed the below version of the Firefox browser on my Windows machine of 64 bits. You need all these details to download proper geckodriver executable file.

Let’s find a compatible version of geckodriver for my installed version of firefox. Remember this is just for reference. These versions will be changed with time. So just to follow the above process and download the correct result.

I will download for Windows – 64 bits. You can refer to the names below to distinguish. For windows, it has “win64” or “win32” in names. Just click on link and it will start downloading. It is a zipped file which you need to unzip. After unzip you will get a geckodriver.exe file as exe is extension of exeutable file on Windows. For Mac and Linux there will be no extension as they follow permission based capability to identify an executable file.

Note:- You can rename this file whatever you want. There is no restrictions that you can not change its name. Many beginners get confuse on this. You just need to use changed name in your program.

Before launching a Firefox browser you need to let WebDriver know explicitly the location of geckodriver executable file. As of now, we will add the path of geckodriver as a system property. There are some other ways as well which we will see later. Any Sytem property is set as a key value pair and to set path of geckodriver, selenium WebDriver has a key as “webdriver.gecko.driver”. Remeber you can not set key to some other name.

Remember we need to set a path of geckodriver with the extension of it if available. It is needed for Windows but for Linux and Mac you need to give it executable permission.

package BasicSeleniumConcepts;

import org.openqa.selenium.firefox.FirefoxDriver;

public class LaunchFirefoxBrowser {
        
        public static void main(String[] args) {
                
                // Set the path of geckodriver with extension for windows
                System.setProperty("webdriver.gecko.driver", "C:\\Users\\amomahaj\\Downloads\\geckodriver-v0.26.0-win64 (1)\\geckodriver.exe");
                FirefoxDriver firefoxDriver = new FirefoxDriver();
                firefoxDriver.get("https://www.google.com/");
        }

}

Now you will be able to launch Firefox browser successfully and it will launch Google.

Do not worry about seeing these red lines. They are just logs. You can ignore as of now. It has some importamt message which will see later.

You can download/clone the above sample project from here.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: REST Assured Tutorial 51 – How To Retrieve and Assert Content-Type of Response in Rest Assured
Next Post: Git Tutorial 18 – What Is A Detached Head In Git?

Related Posts

skyscreamer jsonassert tutorials Uncategorized
Selenium Interview Question 2 – Can Selenium Be Used For API Automation? Uncategorized
4. Data Structure Programs – Delete Node From Unsorted LinkedList In Java Uncategorized
March 30, 2018 – Make Selenium Easy Uncategorized
March 2, 2019 – Make Selenium Easy Uncategorized
chrome Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark