Skip to content

Selenium WebDriver Automation Skill

Automate browsers with Selenium — the most widely-used browser automation framework.

Installation

pip install selenium

Selenium 4.6+ includes automatic driver management (no manual ChromeDriver download needed).

Core Patterns

Open a page

from selenium import webdriver

driver = webdriver.Chrome()  # Auto-downloads matching ChromeDriver
driver.get("https://example.com")
print(driver.title)
driver.quit()

Headless mode

from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)

Find elements and interact

from selenium.webdriver.common.by import By

driver.find_element(By.ID, "username").send_keys("my_user")
driver.find_element(By.ID, "password").send_keys("my_pass")
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()

Wait for elements

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, ".results"))
)

# Wait for clickable
button = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.ID, "submit"))
)
button.click()

Extract data

heading = driver.find_element(By.TAG_NAME, "h1").text
link = driver.find_element(By.CSS_SELECTOR, "a.profile").get_attribute("href")
items = driver.find_elements(By.CSS_SELECTOR, ".product-card")
for item in items:
    name = item.find_element(By.CSS_SELECTOR, ".name").text
    price = item.find_element(By.CSS_SELECTOR, ".price").text

Screenshots

driver.save_screenshot("screenshot.png")
element = driver.find_element(By.ID, "chart")
element.screenshot("chart.png")

Execute JavaScript

driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
result = driver.execute_script("return document.title")

Connect to existing browser (debug port)

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options=options)

Manage cookies

cookies = driver.get_cookies()
driver.add_cookie({"name": "key", "value": "val"})
driver.delete_all_cookies()

Multiple tabs

driver.execute_script("window.open('https://example.com', '_blank')")
driver.switch_to.window(driver.window_handles[1])  # Switch to new tab
driver.switch_to.window(driver.window_handles[0])  # Back to first tab

Locator strategies

StrategyExample
By.IDfind_element(By.ID, "email")
By.CSS_SELECTORfind_element(By.CSS_SELECTOR, "div.card > h2")
By.XPATHfind_element(By.XPATH, "//button[contains(text(),'Submit')]")
By.CLASS_NAMEfind_element(By.CLASS_NAME, "product-title")
By.TAG_NAMEfind_elements(By.TAG_NAME, "li")
By.LINK_TEXTfind_element(By.LINK_TEXT, "Click here")

Prefer By.CSS_SELECTOR — it's faster and more readable than XPath.

Common errors

ErrorFix
"SessionNotCreatedException"Chrome and ChromeDriver version mismatch; update Selenium to 4.6+ for auto-management
"NoSuchElementException"Element doesn't exist or hasn't loaded; use WebDriverWait
"ElementNotInteractableException"Element exists but can't be clicked; scroll to it or wait for visibility
"StaleElementReferenceException"Page has changed since element was found; re-find the element

Important notes

  • Always call driver.quit() when done to prevent zombie Chrome processes
  • Selenium does NOT auto-wait; always use WebDriverWait for dynamic content
  • Use find_elements (plural) when you expect multiple results; it returns [] instead of raising an error
  • For Selenium 4.x, use Service class: webdriver.Chrome(service=Service(path), options=options)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall