Introduction to Selenium WebDriver
When to use Selenium
Section titled “When to use Selenium”Use Selenium when:
- content is rendered by JavaScript
- you must interact with forms/buttons
For static pages, prefer requests + BeautifulSoup.
Minimal example
Section titled “Minimal example”from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome() # requires chromedriver setup
try:
driver.get("https://example.com")
h1 = driver.find_element(By.TAG_NAME, "h1")
print(h1.text)
finally:
driver.quit()- Driver setup differs by OS
- Consider headless mode for automation jobs
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – List Files with os.listdir
Section titled “Exercise 1 – List Files with os.listdir”Exercise 2 – Join Paths with os.path.join
Section titled “Exercise 2 – Join Paths with os.path.join”Exercise 3 – Write and Read a File
Section titled “Exercise 3 – Write and Read a File”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading