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
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
next we start the session by instatiating driver object
driver = webdriver.Chrome(options=Options, service=ChromeService(ChromeDriverManager().install()))
the script above will install driver browser automatically,
then, lets call the driver object to take action on google.com
driver.get("https:www.google.com")
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")
if you have arrived at this step, then your screen will be the same as this image
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)