Skip to content

Automating UI Tests with Selenium & Python

  • you must test real browser rendering
  • you need to click, type, and navigate
  • pages are dynamic
selenium_smoke.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
 
 
def test_homepage_title():
    driver = webdriver.Chrome()
    try:
        driver.get("https://example.com")
        h1 = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.TAG_NAME, "h1"))
        )
        assert "Example" in h1.text
    finally:
        driver.quit()
  • Prefer explicit waits
  • Use stable selectors (id, data-testid)
  • Keep UI tests few (test pyramid)

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading