Selenium Automatically Get Driver

Profile picture for user arilio666

Let us discuss how we can automatically update the driver on the go and proceed to the test without manual effort.

  • Selenium WebDriver provides a way to automatically locate and download the appropriate driver executable for your browser using the WebDriverManager library.
  • WebDriverManager is a Java library that allows you to automatically manage the binary versions of different web drivers. It is an open-source project and can be used to avoid the manual steps of downloading and configuring the web drivers. This is especially useful when running tests on different platforms and different browsers.
  • To use WebDriverManager, you must add the library to your project's classpath and import the relevant classes. Here's an example of how to use WebDriverManager to download and configure the ChromeDriver executable automatically:
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
public class Example {
   public static void main(String[] args) {
       // Configure and download ChromeDriver
       // Create a new instance of ChromeDriver
       WebDriver driver = new ChromeDriver();
       // Use the driver as usual
       // Close the browser
  • This will automatically download the appropriate version of ChromeDriver and configure it for you.

Note that the WebDriverManager must be added to the project dependencies. If you are using maven, you can add the following to your pom.xml file:

  • WebDriverManager also supports other browsers such as firefox, internet explorer, opera, safari, etc. You can also configure the version and architecture of the driver. Refer to their documentation for more details.