Selenium
Overview
Selenium WebDriver is a language-neutral API and W3C protocol for driving real browsers (Chrome, Firefox, Edge, Safari) programmatically. It has official bindings for Java, Python, C#, Ruby, JavaScript, and Kotlin, and scales out via Selenium Grid. Read this when automating cross-browser UI tests, locating and interacting with elements, handling explicit waits, frames, and alerts, or distributing runs across machines.
Official sources
Install / setup
pip install selenium
Source: https://www.selenium.dev/documentation/webdriver/getting_started/install_library/ (Java uses the Maven org.seleniumhq.selenium:selenium-java dependency; drivers are auto-managed by Selenium Manager).
Core concepts
- WebDriver — the session object that launches and commands a browser per the W3C protocol.
- Locators —
By.id, By.cssSelector, By.xpath, etc. find elements on the page.
- WebElement — handle for an element you can
click(), send_keys(), or read text from.
- Explicit waits —
WebDriverWait + expected conditions poll until an element is ready.
- Selenium Manager — built-in tool that downloads matching browser drivers automatically.
- Selenium Grid — runs tests remotely and in parallel across browsers/OSes via a hub/nodes.
- Frames & windows —
switch_to.frame() / switch_to.window() change the driver's focus.
- Actions API — chains advanced keyboard/mouse interactions (hover, drag, key combos).
Best practices
Common pitfalls
NoSuchElementException on dynamic pages → wait with WebDriverWait + expected conditions.
- Mixing implicit and explicit waits causes unpredictable timeouts → use explicit waits only.
- Stale element after DOM re-render → re-find the element instead of reusing the handle.
Examples
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/")
assert "Selenium" in driver.title
driver.find_element(By.CSS_SELECTOR, "a.navbar-brand")
driver.quit()
Further reading
Related skills
- ../playwright — modern auto-waiting cross-browser alternative
- ../cypress — in-browser JavaScript E2E framework
- ../puppeteer — Chrome/Firefox DevTools-Protocol automation
1---2name: selenium3description: Selenium WebDriver is the W3C-standard browser-automation API for controlling real browsers across Java, Python, C#, Ruby, and JavaScript; consult when writing cross-browser UI tests, locating elements, handling waits/frames/windows, or running tests with Selenium Grid and WebDriver drivers.4domain: stack5category: testing6tags: [selenium, webdriver, browser-automation, e2e, cross-browser, grid, ui-testing]7official_sources:8 - https://www.selenium.dev/documentation/webdriver/getting_started/9 - https://github.com/SeleniumHQ/selenium10 - https://www.selenium.dev/documentation/webdriver/getting_started/install_library/11verified: 2026-06-1712metadata:13 source: https://skillmd.com/skills/gabriel7silva/selenium14---1516# Selenium1718## Overview19Selenium WebDriver is a language-neutral API and W3C protocol for driving real browsers (Chrome, Firefox, Edge, Safari) programmatically. It has official bindings for Java, Python, C#, Ruby, JavaScript, and Kotlin, and scales out via Selenium Grid. Read this when automating cross-browser UI tests, locating and interacting with elements, handling explicit waits, frames, and alerts, or distributing runs across machines.2021## Official sources22- Docs: https://www.selenium.dev/documentation/webdriver/getting_started/23- Repo: https://github.com/SeleniumHQ/selenium24- Install: https://www.selenium.dev/documentation/webdriver/getting_started/install_library/2526## Install / setup27```bash28pip install selenium29```30Source: https://www.selenium.dev/documentation/webdriver/getting_started/install_library/ (Java uses the Maven `org.seleniumhq.selenium:selenium-java` dependency; drivers are auto-managed by Selenium Manager).3132## Core concepts33- **WebDriver** — the session object that launches and commands a browser per the W3C protocol.34- **Locators** — `By.id`, `By.cssSelector`, `By.xpath`, etc. find elements on the page.35- **WebElement** — handle for an element you can `click()`, `send_keys()`, or read text from.36- **Explicit waits** — `WebDriverWait` + expected conditions poll until an element is ready.37- **Selenium Manager** — built-in tool that downloads matching browser drivers automatically.38- **Selenium Grid** — runs tests remotely and in parallel across browsers/OSes via a hub/nodes.39- **Frames & windows** — `switch_to.frame()` / `switch_to.window()` change the driver's focus.40- **Actions API** — chains advanced keyboard/mouse interactions (hover, drag, key combos).4142## Best practices43- Use explicit waits over `sleep`; avoid deprecated implicit+explicit mixing (https://www.selenium.dev/documentation/webdriver/waits/).44- Prefer stable locators (id, name, data attributes) over brittle XPath (https://www.selenium.dev/documentation/webdriver/elements/locators/).45- Always `driver.quit()` to release the browser and driver process (https://www.selenium.dev/documentation/webdriver/drivers/).46- Apply the Page Object pattern to isolate selectors from test logic (https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/).4748## Common pitfalls49- `NoSuchElementException` on dynamic pages → wait with `WebDriverWait` + expected conditions.50- Mixing implicit and explicit waits causes unpredictable timeouts → use explicit waits only.51- Stale element after DOM re-render → re-find the element instead of reusing the handle.5253## Examples54```python55from selenium import webdriver56from selenium.webdriver.common.by import By5758driver = webdriver.Chrome()59driver.get("https://www.selenium.dev/")60assert "Selenium" in driver.title61driver.find_element(By.CSS_SELECTOR, "a.navbar-brand")62driver.quit()63```6465## Further reading66- https://www.selenium.dev/documentation/webdriver/waits/ — waiting strategies67- https://www.selenium.dev/documentation/grid/ — distributing tests with Grid6869## Related skills70- ../playwright — modern auto-waiting cross-browser alternative71- ../cypress — in-browser JavaScript E2E framework72- ../puppeteer — Chrome/Firefox DevTools-Protocol automation