Executing the TestsAutomated Chrome Driver Updates in C# Selenium

Automated Chrome Driver Updates in C# Selenium

Let WebDriverManager fetch and update the Chrome driver for you.

WebDriverManager Overview

WebDriverManager is an open-source Java library that manages the drivers required by Selenium WebDriver. It automates tasks, such as downloading, setting up, and maintaining these drivers, making them available for your testing needs.

Diagram connecting Selenium C# logo to Chrome browser icon with gear symbols

Downloading WebDriverManager

Open the Package Manager console by navigating to Tools > NuGet Package Manager > Package Manager Console.

In the Package Manager Console, run the following command:

Install-Package WebDriverManager

Press Enter to execute the command. NuGet will download and install the WebDriverManager package in your project. After installing the package, you can use WebDriverManager in your C# code to manage the WebDriver binaries for Selenium in your project.

Using WebDriverManager

After installation, you can use WebDriverManager.Net to manage WebDriver binaries for your application or test automatically.

Add the following code while creating Chrome session to check for the latest version of the WebDriver binary file and download the binary WebDriver if it is not already present on your system:

new DriverManager().SetUpDriver(new <Driver>Config());

Depending on your browser replace <driver> with the name of the driver you wish to use.

For example, run the following code for a Chrome driver. Run the following code for an Edge driver

DriverManager().SetUpDriver(new ChromeConfig());

The preceding codes initializes and sets up the WebDriver for the specified browser such as Chrome or Edge, using the WebDriverManager library.