How to Run Selenium Test on Firefox?
Last Updated :
24 Apr, 2025
Selenium is a popular open-source tool for automating web browser interactions. Firefox is a fast and secure web browser developed by Mozilla. Firefox uses GeckoDriver to control and interact with Firefox during automated testing. GeckoDriver is a component of the Selenium automation framework that allows communication between the Selenium WebDriver and the Firefox web browser.
What is GeckoDriver?
GekoDriver is designed for interacting with the Mozilla Firefox web browser, it acts as a bridge between the Selenium WebDriver API and the internal communication protocols of Firefox. Allowing developers and testers to automate interaction with Firefox.
Why is GeckoDriver Used?
GeckoDriver is used to automate web testing with the Firefox browser.
- It allows you to control browser behavior and perform actions on web elements.
- GeckoDriver can be used with various programming languages, such as Java, Python, Ruby, etc.
Running Tests on Firefox
Step 1: Setup Test EnvironmentÂ
1. Install Java on your system.
2. After installing Java on your system or already installing, verify the installation by opening a command prompt and typing:
Java -version
3. Install Eclipse IDE on your system.
4. Install Selenium WebDriver for Java on your system.
Step 2: Download GeckoDriver
1. Â Go to the Mozilla GeckoDriver GitHub page.

2. Download the latest version of GeckoDriver that is compatible with your installed version of Firefox. Extract the zip file and copy the path of the geckodriver.exe (e.g., D:/geckodriver-v0.33.0-win64/geckodriver.exe).

Step 3: Configure the Project
1. Create a new Java project in Eclipse IDE. In Eclipse, go to File > New > Java Project. Give a name to your project, such as `SeleniumTest`, and click Finish.
2. Add the downloaded Selenium JAR files to your Java project’s build path. Select all the jar files and click Apply and close.

3. Create a new Java class in the project. In Eclipse, right-click on the src folder under your project name and select New > Class. Give a name to your class, such as `TestFirefox`, and click Finish.

3. Import the required packages
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
4. Set the system property for FirefoxDriver (path to firefoxdriver executable).
(e.g.,D:/geckodriver-v0.33.0-win64/geckodriver.exe).
System.setProperty("webdriver.gecko.driver", "D:/geckodriver-v0.33.0-win64/geckodriver.exe");
5. Create an instance of FirefoxDriver.
WebDriver driver = new FirefoxDriver();
Below is the Java program to search on Firefox:
Java
// Java program to search on Firefox
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestFirefox {
public static void main(String[] args)
{
// Set the path of the geckodriver executable
System.setProperty(
"webdriver.gecko.driver",
"D:/geckodriver-v0.33.0-win64/geckodriver.exe");
// Create an instance of FirefoxDriver class
WebDriver driver = new FirefoxDriver();
// Navigate to a web page
driver.get("https://www.google.com/");
// Find the search box element by its name
WebElement element
= driver.findElement(By.name("q"));
// Enter a search query
element.sendKeys("GeeksforGeeks");
// Submit the form
element.submit();
// Wait for the page to load
try
{
Thread.sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
// Find all the search result links using XPath
List<WebElement> searchResults
= driver.findElements(By.xpath(
"//div[@class='tF2Cxc']//a[@href]"));
// Check if there are search results
if (searchResults.size() > 0)
{
// Click on the first link (index 0)
searchResults.get(0).click();
}
else
{
System.out.println("No search results found.");
}
// Get the title of the current page
String title = driver.getTitle();
// Print the title
System.out.println("Page Title: " + title);
// Close the browser
driver.quit();
}
}
Output:
.gif)
Similar Reads
How to get rid of Firefox logging in Selenium?
When utilizing Selenium for automated browser tests, Firefox logging refers to the log output that is produced by the Firefox browser and the gecko driver. These logs encompass various types of information such as: Browser Logs: Messages generated by the Firefox browser itself, including console out
4 min read
How to Automate TestNG in Selenium?
TestNG is an open-source test automation framework for Java, designed to make the process of testing more efficient and effective. Standing for "Next Generation," TestNG offers advanced features like annotations, data-driven testing, and parallel execution. When combined with Selenium, it provides a
4 min read
How to set Proxy in Firefox using Selenium WebDriver?
In todayâs fast-paced digital world, ensuring that web applications are tested under various network conditions is crucial. Setting up a proxy in Firefox using Selenium WebDriver allows testers to capture traffic, simulate different network environments, and comply with strict corporate policies, ma
4 min read
How to create Selenium test cases
Selenium IDEÂ is an open-source tool that is widely used in conducting automated web testing and browser automation. This tool is intended mainly for Web Application testers and developers to develop, edit, and run automated test cases for Web Applications. Table of Content What are Selenium test cas
6 min read
How to Test Chrome Extensions in Java Selenium?
Testing Chrome extensions is critical as it helps confirm their capabilities and efficiency. This article will explain how to test Chrome extensions using Java Selenium, a well-known web testing tool. Table of Content Setting Up the EnvironmentBasics of Selenium WebDriverWhat Are Chrome Extensions?P
6 min read
How to create nested test suites for Selenium IDE?
When automating browser tests using Selenium IDE, it's important to structure your tests efficiently. A common approach for handling complex test scenarios is to create nested test suites. Test suites allow you to organize multiple tests and execute them together, while nested test suites give you e
2 min read
How to Refresh Firefox to Reset?
When you work on different Web Browsers, there is one famous practice present to Refresh the Web Browser oftentimes to get new updates on that page. However, for the Firefox Web Browser, there are two kinds of Refresh Operations present. One is the traditional one, and another is the "Firefox Refres
4 min read
Selenium IDE-Login Test
In today's world of software development, ensuring seamless user journeys is crucial. Login functionality lies at the heart of most web applications, making robust testing indispensable. This guide introduces us to the Selenium IDE, a powerful tool for automating login tests and streaming our softwa
6 min read
Run Selenium Tests with Gauge
Gauge is an open-source framework for test automation that is especially useful for Behavior Driven Development (BDD). It is characterized by its simplicity, scalability, and compatibility with other languages, such as Java, C#, and JavaScript. Gauge and Selenium work together to provide reliable, u
5 min read
How to Take Screenshots on Firefox? [ 3 Ways ]
While working on Web Browsers, often we come across different important information that should be kept for the future. Now all the items on the Browsers like Firefox are not downloadable. In such cases, Screenshots on Firefox will be the best way to keep that item with you for a lifetime. In most c
4 min read