DEV Community

Cover image for How to manage browser driver with Web Driver Manager
Muchamad Faiz for Zetta

Posted on

How to manage browser driver with Web Driver Manager

In this article i will explain how to use Web Driver Manager to manage browser driver easily

Background

when we make a project using selenium library every time there is a newer version of the driver we need to download it and we have to set the corresponding executable path explicitly. After that, we make object from the driver and continue with the code we want to run. these steps become complicated as we need to repeat these steps out every time the versions change.So therefore, we use WebDriverManager to easily manage it.

Task

Create a simple session to open google.com and search with keyword "web scrapping"

Getting Started

assuming python is intalled on your machine or virtual environment, then you must install WebDriverManager and selenium

pip install webdriver-manager
pip install selenium
Enter fullscreen mode Exit fullscreen mode

after that on code editor lets import all library we need

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
Enter fullscreen mode Exit fullscreen mode

next we start the session by instatiating driver object

driver = webdriver.Chrome(options=Options, service=ChromeService(ChromeDriverManager().install()))
Enter fullscreen mode Exit fullscreen mode

the script above will install driver browser automatically,
Image description
then, lets call the driver object to take action on google.com

driver.get("https:www.google.com")
Enter fullscreen mode Exit fullscreen mode

and lets find element search and send key "web scraping" on it

search_el = driver.find_element(By.CSS_SELECTOR,"input[title='Search']")
search_el.send_keys("web scrapping")
Enter fullscreen mode Exit fullscreen mode

if you have arrived at this step, then your screen will be the same as this image

Web Scraping

Conclusion

now we know that WebDriverManager automates the browser setup in the Selenium code and this make the difficult steps to store newer version of driver become automatic so we can focus on our execution script rather than browser settings

Github :https://github.com/muchamadfaiz
Email : muchamadfaiz@gmail.com

Top comments (0)