Home » Software Testing » Automation Testing » Selenium WebDriver Tutorial » WebDriverManager: New Way to handle driver binaries in Selenium
hypericum with lush green leaves near nutmeg and cinnamon

WebDriverManager: New Way to handle driver binaries in Selenium

What is WebDriverManager?

WebDriverManager is an open-source library which is used to automate the handling of browser driver binaries. User can add this library in their selenium project using a build tool like Maven or Gradle depending on your project.

So let’s talk about the advantages or the task which WebDriverManager handles.

  • Checks the version of browser installed on your machine.
  • Download the driver binary if needed as per the current version of browser to run your selenium script in browser.
  • It matches the version of binary and browser and if it doesn’t work anyway then it takes recent browser driver binary (chromedriver.exe or geckodriver.exe)
  • It removes the dependency on driver binary on local,

Why we are using this WebDriverManager?

To run selenium script in the browser we need to download driver binary from the official site of Browser. This could be ‘chromedriver.exe’ for Chrome and ‘geckodriver.exe’ and similarly, we have many of the driver binary which needs to be downloaded to run the script in any of the browsers.
But we are not stopping here and our problem is not resolved. But we need to add two lines of code
1- System path for Driver like this. For Chrome Browser we need to put this line of code. Read More

For Firefox we need to add this line.

For all other browser, it could be something like this

2- Initializing the browser instance. Which looks like this

But we are not sure that next morning this script is going to work on Chrome/Firefox/Edge/Other Browser or not if browse version is updated.
But why this is going to happen. This is always going to happen due to the mismatch of driver binary and the browser version. Then we could be a possible way to move ahead.
So the answer will be download and set the system path and run the script, Might be it will work.

This is the reason, Boni Garcia came up with this WebDriverManager library which automates this complete process of downloading binary and matching it with the version of the browser.

How to add WebDriverManager Dependency In Selenium Project?

There are three ways to add WebDriverManager in project.

  • By Adding Maven Dependency In POM: If you are using maven as build tool in that case we need to add this dependency in pom.xml
  • By Adding WebDriverManager dependency in build.gradle file like this

Once we perform these two steps, we are good to create our first script.

How to initialize the WebDriverManager instance in script?

Use this code in your eclipse and it will launch the chrome browser without setting up System properties for chrome

1- In above script, WebDriverManager has been initialized for Chrome Browser through line of code

2- So above line will setup the driver binary for chrome. Similarly if we need to initialize other browser then here is the list of initialization for individual browser

3- After adding WebDriverManager initialization, our code will be same as we use to write previously using System property.

Along with this WebDriverManager also provide one generic driver manager which is parameterized using Selenium Driver Class. Have a look on this code

So In above code, we can see that first we have created Selenium Driver Class of Chrome browser by writing this line of code

After this driver class instance is being passed to WebDriverManager’s getinstance method as parameter like this

But above initialization can also be written like this using enumeration DriverManagerType, So above two line of code can be written in a single line

What if we want to keep specific version of driver binary or browser version?

This library has provided a way to use a specific version of the driver as well as browser

So let’s say you want to run some older version of chromedriver or any other browser driver, in that case, you need to write the code like this

So in place of version 86.0.4240.22, you can put any of the version of chromedriver version which you can see on this URL
Similarly, in place of using driver version, we can use browser version to select any specific version of the browser, So code will look like this

So if you want to learn something more about WebDriverManager in that I would suggest you, use this link and read this in detail.

Laptop Affiliate Link: Lenovo Ideapad S540
Configuration : Processor: i5 10th gen, RAM: 8GB HardDriver : 1tb hdd + 256 gb SSD , Operating System: Windows 10 Home Office: 2019 & NVIDIA: 2GB

1 thought on “WebDriverManager: New Way to handle driver binaries in Selenium”

  1. Pingback: How To Run Selenium Tests In Brave Browser Using ChromeDriver?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top