Automate Browser Driver Management with WebDriverManager: A Step-by-Step Guide
Introduction
Web automation in Java is straightforward in concept: open a browser and interact with a web page. However, a hidden challenge emerges from the browser itself: binary compatibility. Each browser requires a specific driver binary, and that binary must exactly match the installed browser version. Even a minor mismatch triggers runtime errors. WebDriverManager is a Java library that solves this by automatically resolving, downloading, and configuring browser drivers for Selenium projects. In this guide, you'll learn how to eliminate manual driver management and make your test setups portable and reliable.

What You Need
- Java Development Kit (JDK) (version 8 or higher)
- A build tool: Maven or Gradle
- Selenium WebDriver dependency (e.g., selenium-java)
- A modern web browser (Chrome, Firefox, Edge, etc.)
- Basic familiarity with Java and writing automated tests
Step-by-Step Guide
Step 1: Understand the Problem with Manual Driver Management
In a traditional Selenium setup, you specify the driver path explicitly using System.setProperty. For example, for Chrome:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
This approach works initially but doesn't scale. Every time your browser updates, you must manually download and replace the driver. In shared environments like CI/CD pipelines or team projects, maintaining consistent driver versions becomes a nightmare. Hardcoded paths also make your code less portable across different machines. WebDriverManager removes these burdens by handling driver resolution dynamically.
Step 2: Add WebDriverManager as a Dependency
Include WebDriverManager in your project using your build tool.
For Maven, add this to your pom.xml:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>6.3.3</version>
<scope>test</scope>
</dependency>
For Gradle, add to your build.gradle:
dependencies {
testImplementation("io.github.bonigarcia:webdrivermanager:6.3.3")
}
Make sure to check for the latest version.
Step 3: Configure WebDriverManager in Your Code
Instead of setting system properties manually, you call a static method from WebDriverManager. For Chrome:
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverSetup {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
// Now you can safely create a ChromeDriver instance
WebDriver driver = new ChromeDriver();
}
}
WebDriverManager will:
- Detect your installed browser version
- Find the matching driver version from the online repository
- Download the driver if not already cached
- Set the correct system property automatically
Step 4: Create and Use the WebDriver
After calling setup(), you can directly instantiate the driver. Here’s a complete example that opens Google’s homepage:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class QuickTest {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println("Page title: " + driver.getTitle());
driver.quit();
}
}
Run it – you’ll see the browser launch automatically with no driver path errors.
Step 5: Integrate with Test Frameworks
WebDriverManager works seamlessly with JUnit 5 or TestNG. For example, in a JUnit 5 test:
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class GoogleSearchTest {
WebDriver driver;
@BeforeEach
void setUp() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
@Test
void testGoogleSearch() {
driver.get("https://www.google.com");
// Your assertions…
}
@AfterEach
void tearDown() {
driver.quit();
}
}
Step 6: Explore Advanced Features (Optional)
WebDriverManager goes beyond basic driver setup. It offers:
- Driver caching control – drivers are stored locally, preventing repeated downloads. You can clear or customize the cache path.
- Docker support – use
WebDriverManager.chromedriver().browserInDocker()to run browsers inside Docker containers. - Browser version resolution – e.g.,
.browserVersion("120")to force a specific version. - Proxy configuration – for corporate environments.
For Firefox, call WebDriverManager.firefoxdriver().setup(); for Edge, WebDriverManager.edgedriver().setup().
Tips for Success
- Keep WebDriverManager up to date – newer versions support the latest browsers and fix compatibility issues.
- Use caching wisely – the default cache is per user; in CI environments, consider clearing the cache periodically to force fresh downloads.
- Combine with Selenium Manager – though WebDriverManager is more feature-rich, you can also rely on Selenium's built-in manager for simpler setups.
- Avoid hardcoding driver paths – even in fallback code; let WebDriverManager handle everything.
- Test across browsers – use the same pattern for Chrome, Firefox, and Edge to ensure cross‑browser compatibility.
- Document your dependency version – specify the exact WebDriverManager version in your build file to avoid surprises from updates.
By following these steps, you’ll eliminate the pain of manual driver management and create robust, portable Selenium automation scripts.
Related Articles
- New Framework for AI Transparency: Decision Node Audit Breaks Down the Black Box
- 10 Revolutionary Facts About Building Homes with Robot Inchworms and Giant LEGO Bricks
- Transform Your Old Smartphone Into a Wall-Mounted Home Presence Sensor
- Automate Your Cleaning: A Step-by-Step Guide to Linking Matic Robot Vacuum with Apple Home
- ByteDance Unveils Astra: AI Breakthrough Solves Robot Navigation in Complex Indoor Spaces
- From Lab Marvels to Real-World Tools: The Hard Path for Bionic Technology
- DAIMON Robotics Unleashes Largest Tactile Dataset to Give Robot Hands a Sense of Touch
- Cloud-Free IR Control for Your Dumb Appliances: Q&A Guide