How to Automate Browser Driver Management in Selenium with WebDriverManager

By

Introduction

Automating web interactions in Java with Selenium is straightforward until you face the persistent problem of browser driver compatibility. Every time a browser updates, its corresponding driver must be updated manually, and even a minor mismatch between the driver version and the installed browser leads to runtime errors. Hardcoding driver paths in your code also makes it fragile across different environments, such as shared development machines and CI/CD pipelines. WebDriverManager solves this by programmatically handling driver resolution, download, and configuration. This guide walks you through setting up WebDriverManager in a Java-based Selenium project, step by step.

How to Automate Browser Driver Management in Selenium with WebDriverManager
Source: www.baeldung.com

What You Need

Step-by-Step Guide

Step 1: Understand Why Manual Driver Management Is Problematic

Before jumping into WebDriverManager, it helps to recognise the pain points it eliminates. In a conventional Selenium setup, you explicitly point to a driver binary using System.setProperty(), like this:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

This approach works locally but quickly becomes a maintenance burden:

WebDriverManager automates the entire process, keeping your tests reliable and portable.

Step 2: Add the WebDriverManager Dependency to Your Build File

Include the WebDriverManager library in your project using your build tool. The library is hosted on Maven Central under the group io.github.bonigarcia.

For Maven (pom.xml):

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>6.3.3</version>
    <scope>test</scope>
</dependency>

For Gradle (build.gradle):

dependencies {
    testImplementation 'io.github.bonigarcia:webdrivermanager:6.3.3'
}

After adding the dependency, refresh your project so that the library becomes available. You can verify the latest version on the WebDriverManager GitHub page.

Step 3: Replace Manual Driver Setup with WebDriverManager Calls

Now modify your test code to use WebDriverManager instead of System.setProperty(). The library provides a fluent API for each browser. For example, to launch Chrome:

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebDriverManagerDemo {
    public static void main(String[] args) {
        // Let WebDriverManager handle the driver
        WebDriverManager.chromedriver().setup();
        
        // Now create the driver object normally
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        
        // Your test actions...
        driver.quit();
    }
}

The .setup() method does everything: it detects your installed Chrome version, downloads the matching ChromeDriver if needed, and sets the correct system property. Similar methods exist for other browsers: firefoxdriver(), edgedriver(), operadriver(), and safaridriver().

Step 4: Run Your Tests and Observe the Automatic Driver Resolution

Execute the code above. On the first run, WebDriverManager will download the appropriate driver binary to a local cache (usually under ~/.cache/selenium/). Subsequent runs reuse the cached version unless a new browser update triggers a fresh download. You’ll notice:

How to Automate Browser Driver Management in Selenium with WebDriverManager
Source: www.baeldung.com

If you encounter issues, check the browser version and ensure WebDriverManager’s version matrix supports it. The library typically supports the latest stable browser versions.

Step 5: (Optional) Integrate WebDriverManager with CI/CD Pipelines and Docker

WebDriverManager shines in automated environments. For example, in a Jenkins or GitLab CI pipeline, you don’t need to pre‑install driver binaries on the build agents. The library downloads the correct driver on the fly. To use it with Dockerized browsers (e.g., Selenium Grid containers), you can configure WebDriverManager using its advanced APIs:

WebDriverManager.chromedriver().browserInDocker().setup();

This instructs the library to spin up a Docker container running the browser, eliminating the need for a local installation. You can also adjust caching policies and proxy settings for corporate networks. Refer to the official documentation for more advanced options.

Tips and Best Practices

By following this guide, you eliminate one of the most common headaches in Selenium automation. WebDriverManager makes your test code cleaner, more portable, and truly maintainable – whether you're developing locally or running thousands of tests in the cloud.

Related Articles

Recommended

Discover More

Microsoft's May 2026 Patch Tuesday: 139 Updates, No Zero-Days, but Critical RCEs Demand Urgent ActionMastering Game Discovery on GeForce NOW: A Step-by-Step Guide to Using Subscription Labels and New ReleasesA Practical Guide to Surviving a Cyberattack on Canvas During FinalsTurboQuant: Google's New Approach to Efficient Key-Value Compression for LLMs and Vector SearchGödel's Unknowability Unlocks Unbreakable Codes: Mathematicians Reveal New Encryption Method