With the augment of Selenium Webdriver 3, the onus to provide driver executables for the browser fell on the shoulders of browser makers. Also at this time, any browser which followed W3C compliance had to ensure it allowed automation of itself through Selenium. This information is now historical, as we are looking upto the newest version of Selenium on the block Selenium 4.0. But many projects and setups will still be using Selenium 3.0 and currently this topic is for those projects. Whether the new Selenium will bring any change with browser drivers or not that is still not known.
A big issue we all fell into is providing the driver executable for the browser based on the version on our system. Geckodriver which supports firefox has its own set of versions available compatible with every browser, and Chrome seems to be on a spree to release an upteem number of drivers for various versions of Chrome available – have a look – https://chromedriver.chromium.org/downloads, the point to note is that all these releases don’t have a very large span of time available between them.
Boni Garcia’s WebDriverManager comes to help in here to solve the issue of having available the correct driver version for the browser version you have on your system, or the one on which tests are executing. As per its definition available here – https://github.com/bonigarcia/webdrivermanager, it is a library which automate the management of drivers, required by Selenium WebDriver. The WebDriverManager does its magic by performing the following actions –
- Checks the version of the browser available on system[Chrome/Firefox/Edge/Opera..]
- If the current driver version matches, it proceeds else finds the driver version matching the browser version we have.
- Downloads the required driver if absent from WebDriverManager cache (~/.cache/selenium by default), for python module it will be -user.home/.wdm folder.
In this article we will explore the WebDriverManager module in python, this one is created and maintained by Sergey Pirogov. Let us see the steps we will have to do to use this in our code-
1.Use the pip command to install webdriver-manager module for python
2. The next is its usage in a simple python program, let us see how we initialize the driver now-
Let us look at the different logs which got generated by WDM[WebDriverManager] as it instantiated Chrome browser using the correct driver version –