Written by Sümeyye Sever (notes I took while learning Python)
Selenium WebDriver is a popular open-source tool for automating web browsers. It allows developers and testers to write scripts that interact with web pages in the same way a user would, such as clicking buttons, filling out forms, and navigating between pages.
Below is an example of how to use Selenium WebDriver with each find_element method. The example automates searching on a search engine (Google):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
# keeps chrome open
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)
# create the driver and go to google page
driver = webdriver.Chrome(options=chrome_options)
driver.get("<https://www.google.com>")
# find the search box enter the key and press the enter button
search_box = driver.find_element(By.ID, "APjFqb")
search_box.send_keys("Selenium Webdriver tutorial")
search_box.send_keys(Keys.ENTER)
# choose first result click it and go to that page
first_search_result = driver.find_element(By.CLASS_NAME, "kb0PBd")
first_search_result.click()
driver.quit()
Here are some other Selenium WebDriver projects I created during the "100 Days of Code: The complete Python Pro Bootcamp" course from Udemy, available on my GitHub page.
At the end, if you can choose elements without much difficulty, creating bots with Selenium is easy and also very enjoyable.