Skip to content

Introduction to Selenium WebDriver

When to use Selenium

Use Selenium when:

  • content is rendered by JavaScript
  • you must interact with forms/buttons

For static pages, prefer requests + BeautifulSouprequests + BeautifulSoup.

Minimal example

selenium_basic.py
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()
selenium_basic.py
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()

Notes

  • Driver setup differs by OS
  • Consider headless mode for automation jobs

🧪 Try It Yourself

Exercise 1 – List Files with os.listdir

Exercise 2 – Join Paths with os.path.join

Exercise 3 – Write and Read a File

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did