How to add selenium dependency in gradle project?

Posted by

If you’re working on a Gradle project and want to use Selenium, you’ll need to add the Selenium dependency in gradle. This article will guide you through the steps to add Selenium with Gradle.

Steps to Selenium dependency in gradle

Open build.gradle File

First, open your Gradle project in a text editor or an IDE that supports Gradle projects.

Locate the Dependencies Section

Locate the build.gradle file in the root directory of your project. Inside the build.gradle file, find the dependencies section. It is typically defined within the dependencies {} block.

Add Selenium dependency in gradle

Inside the dependencies {} block, add the following line to include the Selenium gradle dependency:

dependencies {
    // Other dependencies...
    testImplementation 'org.seleniumhq.selenium:selenium-java:<version>'

Replace <version> with the desired version of Selenium. For example, to use Selenium 4.0.0, the line should be:

testImplementation 'org.seleniumhq.selenium:selenium-java:4.0.0'

Save the build.gradle File

Save the build.gradle file after adding the Selenium dependency.

Build Your Gradle Project

Gradle will automatically download Selenium dependency the next time you build your project. To trigger a build, run the gradle build command in your project’s root directory.

Example Usage of Selenium 4 with Gradle

Here’s an example of using Selenium 4 with Gradle to perform web automation:

import org.openqa.selenium.WebDriver;

public class SeleniumExample {
    public static void main(String[] args) {
        // Set the path to the chromedriver executable
        System.setProperty("", "path/to/chromedriver");

        // Create a new instance of the ChromeDriver
        WebDriver driver = new ChromeDriver();

        // Navigate to a website

        // Perform actions with the WebDriver
        // ...

        // Close the WebDriver


By following the steps outlined in this article, you can easily add the Selenium dependency to your Gradle project. This enables you to utilize Selenium’s powerful features for web automation, web scraping, and other related tasks. Happy coding with Selenium and Gradle!


What are the different versions of the Selenium Gradle dependency?

The Selenium Gradle dependency is updated on a regular basis. The latest version is 4.9.1. You can find a list of all available versions on the Selenium website.

What are the different types of Selenium Gradle dependencies?

There are two types of Selenium Gradle dependencies:
The implementation dependency is used for dependencies that are required for your project to compile.
The testImplementation dependency is used for dependencies that are only required for your project to run tests.

What are the different ways to use the Selenium Gradle dependency?

You can use the Selenium Gradle dependency in a number of ways. Here are a few examples:
You can use it to create a WebDriver session.
You can use it to interact with web elements.
You can use it to send and receive HTTP requests.

Leave a Reply

Your email address will not be published. Required fields are marked *