WebDriver Manager: Resolve compatibility issues in Selenium Python

Mrudula M
Analytics Vidhya
Published in
3 min readJul 17, 2020
Photo by AbsolutVision on Unsplash

Almost all selenium testers have struggled atleast once to get the Selenium webdriver binaries working with proper versions. We often hear them say, “My automation scripts were working perfectly fine yesterday, but it’s giving me errors today, without any changes! ”. Most of the time this would be due to incompatibility between webdriver and the browser version. We would manually download, unzip and manage these browser drivers for each operating environment, update them when new versions of the binaries or browsers are released. All of this is time consuming and boring! There’s a smarter way of dealing with this and it’s using a library called WebDriver-Manager.

WebDriver-Manager is a free open source library that automatically manages our different browser drivers and saves us all the time and effort spent in manually managing the drivers. Basically what it does is, check for the latest version of the WebDriver binary, download it if it’s not present on your system and then export the required WebDriver environment variables needed by Selenium. It’s very simple and just involves a pip install and 2 lines of code, that’s it!! Lets see how.

Prerequisites: Selenium installed.( Else, you can — pip install selenium)

Install webdriver-manager by running the below command.

pip install webdriver-manager

You can verify if Selenium and Webdriver-manager are installed by running pip list

For Chrome browser, import the ChromeDriverManager and create the driver object as shown below.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

And That’s it ! We are done.(No downloading exe driver file or providing the executable path.) We can directly run our tests as shown below.

When we run the test first time, latest version of chromedriver binary is downloaded and saved in cache and it is reused every time we run tests. If your browser auto updates the version, then the respective chromedriver is auto downloaded and updated when running tests.

If you want to run specific version, then pass the version as follows →

For Firefox browser, use →

from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

With IE, use →

from selenium import webdriver
from webdriver_manager.microsoft import IEDriverManager

driver = webdriver.Ie(IEDriverManager().install())

You can find details for more browsers here.

To conclude, using webdriver manager saves time, eliminates lot of manual work and resolves incompatibility issues making Selenium Automation easier. Happy Automation !!!

P.S. Thanks to Sergey Pirogov for his contribution of the webdriver manager.

--

--

Mrudula M
Analytics Vidhya

An aspiring Python Developer and QA Engineer, Passionate about technology and learning. Mom to an awesome son.