How to Automate Browser Driver Management in Selenium with WebDriverManager

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

  • Java Development Kit (JDK 8 or later) installed on your machine.
  • A Java build tool – either Maven or Gradle.
  • Selenium library added to your project (latest version recommended).
  • A target browser (Chrome, Firefox, Edge, Safari, etc.) that you plan to automate.
  • Basic familiarity with Java and Selenium WebDriver syntax.

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:

  • Every browser update requires you to manually download a matching driver.
  • Hardcoded paths break on other machines or in CI environments.
  • Team members must coordinate driver versions to avoid inconsistencies.
  • You need to handle driver binaries across different operating systems separately.

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
  • No more manual driver downloads.
  • No hardcoded paths – the code works on any machine with the same browser installed.
  • Test execution starts faster after the initial setup.

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

  • Use the latest version – Always update WebDriverManager to the newest stable release to support recent browser updates and security fixes.
  • Leverage caching – The library caches drivers locally, so avoid clearing the cache unless necessary. For CI environments, consider persisting the cache across pipeline runs to save bandwidth and time.
  • Handle multiple browsers – In cross‑browser testing, simply call the appropriate WebDriverManager.*().setup() before each browser initialization.
  • Combine with Selenium Grid – For distributed testing, use WebDriverManager to provision drivers on each node automatically, reducing manual configuration.
  • Know the relationship with Selenium Manager – Selenium 4.6+ includes a built-in Selenium Manager that also automates driver discovery. However, WebDriverManager offers extra features like Docker support and more granular control. Evaluate both based on your needs.
  • Watch out for proxy environments – If your network is behind a proxy, configure the system properties (e.g., http.proxyHost) before calling .setup().

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.

Tags:

Recommended

Discover More

Mastering React Native 0.85: A Guide to the New Animation Backend and Key UpdatesTop Tech Deals: Massive Savings on Galaxy Tabs, S26 Ultra Bundles, and More5 Key Updates in Python 3.15.0 Alpha 5 You Should KnowThe CSS contrast-color() Function Demystified: Common Questions AnsweredOpenTelemetry Adoption Surges as Developers Seek Deeper Observability Beyond Logging