How to Run Gecko Driver in Selenium Using Java?
Last Updated :
23 Jul, 2025
Selenium is a well-known software used for software testing purposes. It consists of three parts: Selenium IDE, Selenium WebDriver, and Selenium Grid. Selenium WebDriver is the most important. Using WebDriver, online website testing can be done. There are three main WebDriver implementations:
- ChromeDriver for Chrome
- GeckoDriver for Firefox
- MS EdgeDriver for Microsoft Edge
In this article, the process of running Gecko WebDriver is implemented. This simple Java program can be run.
What is GeckoDriver in Selenium?
GeckoDriver is a WebDriver implementation for Mozilla Firefox. It translates Selenium commands into actions performed by Firefox, enabling automated browser interactions. GeckoDriver ensures compatibility with Firefox and supports modern web features.
How Does GeckoDriver Work?
GeckoDriver acts as a bridge between Selenium WebDriver and the Firefox browser. Here’s how it works in simple terms:
- Selenium sends a command: For example, to click a button or open a page.
- GeckoDriver processes the command: It takes this instruction and translates it into a language Firefox understands.
- Firefox performs the action: GeckoDriver sends the translated command to Firefox’s engine to execute the action.
- Response is sent back: Once Firefox completes the task, it sends a response to GeckoDriver.
- Selenium gets the result: GeckoDriver passes this response to Selenium, which continues running the test script.
In short, GeckoDriver ensures your Selenium tests can control Firefox smoothly.
How to Download and Install GeckoDriver in Selenium
- Add Maven Dependencies: To use GeckoDriver with Selenium, you first need to add the necessary dependencies to your Maven project.
- Modify Your
pom.xml
: Open your pom.xml
file and add the following dependencies:
Project Setup:
pom.xml
XML
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>GeeksorGeeks</groupId>
<artifactId>SeleniumAutomationGFG</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SeleniumAutomationGFG</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.23.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
</project>
- Note: Replace the version numbers with the latest versions if necessary.
- Save
pom.xml
: After saving, Maven will automatically download the required dependencies and add them to your project. - Ways to Initialize GeckoDriver Using WebDriverManager (Recommended): WebDriverManager simplifies the process by automatically managing the GeckoDriver binary.
Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class FirefoxTest {
public static void main(String[] args) {
// Setup GeckoDriver using WebDriverManager
WebDriverManager.firefoxdriver().setup();
// Create an instance of FirefoxDriver
WebDriver driver = new FirefoxDriver();
// Open a website
driver.get("https://www.example.com/");
// Close the browser
driver.quit();
}
}
Code for Launching Firefox Using GeckoDriver
Here’s a complete example of a Java Selenium script to launch Firefox and navigate to a website:
GoogleSearchTest.java
Java
package basicweb;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class GoogleSearchTest {
public static void main(String[] args) {
// Set up ChromeDriver using WebDriverManager
WebDriverManager.chromedriver().setup();
// Create an instance of ChromeDriver
WebDriver driver = new ChromeDriver();
try {
// Navigate to Google
driver.get("https://www.google.com/");
// Find the search box and enter a search term
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Selenium WebDriver");
// Submit the search
searchBox.submit();
// Find the first result and click on it
WebElement firstResult = driver.findElement(By.cssSelector("h3"));
firstResult.click();
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
Output:
Firefox Driver for Selenium outputLaunch the Firefox Browser Using GeckoDriver in Selenium
Pre-Requisites:
- For running GeckoDriver, the Java jdk version must be installed in the machine previously.
- The latest version of Firefox should be installed.
- It is preferable to install Eclipse IDE on the machine so that running this code will be easier.
- The most important prerequisite is latest GeckoDriver should be downloaded on the machine.
Approach:
- Store the URL: Start by saving Google’s homepage URL in a string variable.
- Set up the browser property: Use the
setProperty()
method to configure the browser. - The first argument specifies the WebDriver being used (in this case, GeckoDriver).
- The second argument is the file path to the
geckodriver.exe
.
Note: If the geckodriver.exe
is in your Eclipse project, the path might look different. Alternatively, you can provide the complete path from File Explorer.
- Create a driver instance: Create a new
WebDriver
object for GeckoDriver. - Open the URL: Use the
get()
method of the WebDriver object to open the Google homepage by passing the URL string. This will launch Firefox and load the page. - Add a delay: Use the
sleep()
method to pause the program briefly, allowing the output to remain visible for a while. - Close the browser: Finally, use the
quit()
method to close the Firefox window and end the program.
By following these steps, you’ll successfully open Google’s homepage in Firefox using Selenium and GeckoDriver:
Java
// Importing All Necessary Items
import java.io.*;
import java.lang.Thread;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirefoxHomePage {
public static void main(String[] args)
{
// Try-Catch Block For Implementing Sleep Method
try {
// String Where Home Page URL Is Stored
String baseUrl = "https://www.google.com//";
// Implementation of SetProperty Method
System.setProperty(
"webdriver.gecko.driver",
"test/resources/geckodriver.exe");
// Creating New Object driver Of Webdriver
WebDriver driver = new FirefoxDriver();
// Calling the Home Page By Using Get() Method
driver.get(baseUrl);
// Delaying The Output
Thread.sleep(2000);
// Closing The Opened Window
driver.quit();
}
catch (Exception e) {
// Catching The Exception
System.out.println(e);
}
}
}
Output:
If the above code is run, then a new Firefox window will be opened. This open window will be controlled by GeckoDriver.exe. In this new window, a golden color stripe can be visible in the search bar of Firefox.
Hence, the program runs successfully.
Conclusion
GeckoDriver is key to automating the Firefox browser with Selenium WebDriver. Setting it up and configuring it properly allows you to test Firefox effectively. With this knowledge, you can easily run automated tests in Java-based Selenium projects, ensuring reliable cross-browser testing for your web applications.
Similar Reads
Software Testing Tutorial Software testing is an important part of the software development lifecycle that involves verifying and validating whether a software application works as expected. It ensures reliable, correct, secure, and high-performing software across web, mobile applications, cloud, and CI/CD pipelines in DevOp
10 min read
What is Software Testing? Software testing is an important process in the Software Development Lifecycle(SDLC). It involves verifying and validating that a Software Application is free of bugs, meets the technical requirements set by its Design and Development, and satisfies user requirements efficiently and effectively.Here
11 min read
Principles of Software testing - Software Testing Software testing is an important aspect of software development, ensuring that applications function correctly and meet user expectations. From test planning to execution, analysis and understanding these principles help testers in creating a more structured and focused approach to software testing,
3 min read
Software Development Life Cycle (SDLC) Software Development Life Cycle (SDLC) is a structured process that is used to design, develop, and test high-quality software. SDLC, or software development life cycle, is a methodology that defines the entire procedure of software development step-by-step. The goal of the SDLC life cycle model is
8 min read
Software Testing Life Cycle (STLC) The Software Testing Life Cycle (STLC) is a process that verifies whether the Software Quality meets the expectations or not. STLC is an important process that provides a simple approach to testing through the step-by-step process, which we are discussing here. Software Testing Life Cycle (STLC) is
7 min read
Types of Software Testing Software testing is a important aspect of software development life-cycle that ensures a product works correctly, meets user expectations, and is free of bugs. There are different types of software testing, each designed to validate specific aspects of an application, such as functionality, performa
15+ min read
Levels of Software Testing Software Testing is an important part of the Software Development Life Cycle which is help to verify the product is working as expected or not. In SDLC, we used different levels of testing to find bugs and errors. Here we are learning those Levels of Testing in detail.Table of ContentWhat Are the Le
4 min read
Test Maturity Model - Software Testing The Test Maturity Model (TMM) in software testing is a framework for assessing the software testing process to improve it. It is based on the Capability Maturity Model(CMM). It was first produced by the Illinois Institute of Technology to assess the maturity of the test processes and to provide targ
8 min read
SDLC MODELS
TYPES OF TESTING