WebDriverManager

If you are use Selenium WebDriver, you will use some browsers such as Chrome, Firefox, Opera,  and Microsoft Edge, first you need to download a binary file which allows WebDriver to handle browsers. In Python, the path to this binary must be set, as follows:

Ex:
chromePath="C:\\BrowserDrivers\\chromedriver.exe"
driver=webdriver.Chrome(executable_path=chromePath)

If the path is not defined or if the path provided is wrong, we will get an exception while running our tests. This is quite annoying since it forces you to link directly this binary file into your source code. In addition, you have to check manually when new versions of the binaries are released. WebDriverManager comes to the rescue, performing in an automated way all this dirty job for you means WebDriverManager by Boni Garcia helps us to manage driver related settings with ease.

It supports browsers such as Chrome, Firefox, Opera, and Microsoft Edge.

All we have to do is download web driver-manager package  through PIP and install into your Python



The following classes are available:
1)   ChromeDriverManager for downloading and installing chromedriver (for Google Chrome).
2)   GeckoDriverManager for downloading and installing geckodriver (for Mozilla Firefox).
3)   OperaChromiumDriverManager for downloading and installing operadriver (for Chromium based Opera browsers).
4)   EdgeDriverManager for downloading and installing edgedriver (for Microsoft Edge).

Script  for Chrome:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver=webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://newtours.demoaut.com")
driver.find_element_by_name(
"userName").send_keys("hello")
driver.find_element_by_name(
"password").send_keys("hello")
driver.find_element_by_name(
"login").click()
print(driver.title)
driver.close()

You have to import ChromeDriverManager for chromeBrowser.
In the above script we are not define any binary file path , just which ever browser you want mentioned that browser Manager while executing installed that binary and execute your script on that browser.
driver=webdriver.Chrome(ChromeDriverManager().install())

Script for Firefox
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver=webdriver.Chrome(GeckoDriverManager().install())

Comments