February 9, 2022

How to use WebDriver manager for efficient management of browser drivers ( Selenium + .Net )

  February 9, 2022

Managing WebDrivers in sync with browser versions is always a problem for an automation tester. 

If we can't control the auto-update of the browser, then the problem becomes worse.

So what if there is a one-point solution for this, in which the automation scripts themselves will download the latest version of the driver for all the browsers.

The solution is WebDriver Manager Nuget in Visual Studio.

Using this we can decide the version of the driver to be downloaded or we can set it to automatically download the latest version on the execution of the script.

When using web driver manager, we don't need to specify the path of the driver. Since it is automatically downloaded to the bin folder.

A complete browser control method using WebDriver Manager is given below.

public static WebDriver _driver;
private readonly IObjectContainer container;

public void DriverManager(string browserValue)
	//Checking browser name
	string browserValue = Settings.BrowserType.ToString().ToLower();

		switch (browserValue)
			case "firefox":

			new WebDriverManager.DriverManager().SetUpDriver(new FirefoxConfig());
			FirefoxOptions FirefxOptions = new FirefoxOptions();

				if (browserValue.Contains("headless"))

			_driver = new FirefoxDriver(FirefxOptions);


			case "ie":
			//Ignore Protected mode settings in IE                               
			new WebDriverManager.DriverManager().SetUpDriver(new InternetExplorerConfig());
			var IEoptions = new InternetExplorerOptions
					IntroduceInstabilityByIgnoringProtectedModeSettings = true,
					// ForceCreateProcessApi = true,
					EnableNativeEvents = true,
					RequireWindowFocus = true,
					IgnoreZoomLevel = true
				_driver = new InternetExplorerDriver(IEoptions);


			case "chrome":

				new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
				ChromeOptions ChrOptions = new ChromeOptions();

				var loggedInUser = Environment.UserName;
				ChrOptions.AddAdditionalOption("useAutomationExtension", false);

				if (browserValue.Contains("headless"))

			_driver = new ChromeDriver (ChrOptions);
			_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);


			case "edge":
				new WebDriverManager.DriverManager().SetUpDriver(new EdgeConfig());
				EdgeOptions Edgoptions = new EdgeOptions();
				Edgoptions.AcceptInsecureCertificates = true;
				_driver = new EdgeDriver(Edgoptions);



				Console.Out.WriteLine("Wrong browser type Entered : " + Settings.BrowserType + ", Please select from Chrome/Chrome+headless/Firefox/Firefox+headless/IE");


		Console.Out.WriteLine("Launched Browser " + Settings.BrowserType);
	_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
	_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15);

This method can be customized to handle any browser with any version from our test scripts.

We can use the below code if we want to specify the version of the driver to download.
new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig(), "97.0.4692.99");
ChromeOptions ChrOptions = new ChromeOptions();

Thanks for reading How to use WebDriver manager for efficient management of browser drivers ( Selenium + .Net )

« Prev Post

No comments:

Post a Comment

How to send email from current Outlook instance using Java + VBScript

If we are using .Net, we can easily access outlook and send emails using its own libraries. But what if we are using Java? Here we can seek ...