Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Run Opera Driver in Selenium Using Java?
Next article icon

How to Run Gecko Driver in Selenium Using Java?

Last Updated : 25 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  1. Selenium sends a command: For example, to click a button or open a page.
  2. GeckoDriver processes the command: It takes this instruction and translates it into a language Firefox understands.
  3. Firefox performs the action: GeckoDriver sends the translated command to Firefox’s engine to execute the action.
  4. Response is sent back: Once Firefox completes the task, it sends a response to GeckoDriver.
  5. 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

  1. Add Maven Dependencies: To use GeckoDriver with Selenium, you first need to add the necessary dependencies to your Maven project.
  2. Modify Your pom.xml: Open your pom.xml file and add the following dependencies:

Project Setup:

Selenium-with-Firefox-Driver

pom.xml

XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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:

Selenium-Firefox-output
Firefox Driver for Selenium output

Launch 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.

Output

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.


Next Article
How to Run Opera Driver in Selenium Using Java?
author
sounetraghosal2000
Improve
Article Tags :
  • Java
  • Software Testing
  • Selenium
Practice Tags :
  • Java

Similar Reads

  • How to Run Opera Driver in Selenium Using Java?
    Selenium is a well-known software used for software testing purposes. Selenium consists of three parts. One is Selenium IDE, one is Selenium Webdriver & the last one is Selenium Grid. Among these Selenium Webdriver is the most important one. Using Webdriver online website testing can be done. Th
    3 min read
  • How to Run Safari Driver in Selenium Using Java?
    Selenium is a well-known software used for software testing purposes. Selenium consists of three parts: Selenium IDE, Selenium Webdriver, and Selenium Grid. Among these, Selenium Webdriver is the most important one. Using Webdriver, online website testing can be done. There are three main Webdrivers
    4 min read
  • How to Run Internet Explorer Driver in Selenium Using Java?
    Selenium is a well-known software used for software testing purposes. Selenium consists of three parts. One is Selenium IDE, one is Selenium Webdriver & the last one is Selenium Grid. Among these Selenium Webdriver is the most important one. Using Webdriver online website testing can be done. Th
    6 min read
  • How to Run Edge Driver in Selenium Using Eclipse?
    Selenium is a well-known software used for software testing purposes. Selenium consists of 3 parts. One is Selenium IDE, one is Selenium Webdriver & the last one is Selenium Grid. Among these Selenium Webdriver is the most important one. Using webdriver online website testing can be done. There
    3 min read
  • How to Open Chrome Browser Using Selenium in Java?
    Selenium is an open-source popular web-based automation tool. The major advantage of using selenium is, it supports all browsers like Google Chrome, Microsoft Edge, Mozilla Firefox, and Safari, works on all major OS, and its scripts are written in various languages i.e Java, Python, JavaScript, C#,
    3 min read
  • How to Handle Alert in Selenium using Java?
    Imagine filling out a form online and accidentally missing some information. You only know if you made a mistake if the website tells you somehow, like with a pop-up message. This article explains what those pop-up messages are called in Selenium (alerts) and how to deal with them in your automated
    6 min read
  • How to Open Microsoft Edge Browser using Selenium in Java?
    Selenium is an open-source popular web-based automation tool. The major advantage of using selenium is, it supports all browsers like Google Chrome, Microsoft Edge, Mozilla Firefox, and Safari, works on all major OS and its scripts are written in various languages i.e Java, Python, JavaScript, C#, e
    3 min read
  • How to click on an image using Selenium in Java?
    Selenium, a popular tool for automating web application testing across browsers, often requires image interaction. In this article we will discuss how to clicking on image using Selenium in Java. PrerequisitesJava Development Kit (JDK) installed.Selenium WebDriver library added to your project.A sup
    3 min read
  • How to download File in Selenium Using java
    Automating the file download process is essential in web automation testing, especially for validating functionalities involving document downloads such as PDFs, images, or CSV files. However, Selenium WebDriver doesn’t directly handle file downloads. To overcome this limitation, we can configure th
    2 min read
  • How to Perform Right-Click using Java in Selenium?
    While automating a website for testing there is always required to perform some right-click or other user actions on the page.  These user actions are one of the most commonly used actions during automation, so selenium provides a way to perform these user actions by the Actions class. How to Perfor
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences