Selenium — Browser Automation Framework and Ecosystem
Selenium is the original browser automation framework for testing web applications. WebDriver API supports Chrome, Firefox, Safari, Edge across Java, Python, C#, Ruby, JavaScript. The industry standard for E2E web testing since 2004.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 42404d19-364b-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Selenium is the original browser automation framework for testing web applications. Its WebDriver API lets you drive Chrome, Firefox, Safari, and Edge programmatically from Java, Python, C#, Ruby, or JavaScript. It has been the industry standard for end-to-end web testing since 2004.
QA engineers, test automation developers, and teams building CI/CD pipelines with browser-based validation all rely on Selenium. It covers the full range from simple smoke tests to complex multi-page user journey validation.
How it saves time or tokens
Selenium replaces manual browser testing with automated scripts that run in seconds. A test suite that would take a QA team hours to execute manually runs in minutes on CI. The WebDriver protocol is a W3C standard, so tests written for one browser generally work across all supported browsers with minimal changes.
How to use
- Install the Selenium client library for your language (pip, npm, Maven, NuGet, or gem).
- Download or configure the browser driver (ChromeDriver, GeckoDriver, etc.) or use Selenium Manager for automatic driver management.
- Write test scripts using the WebDriver API to navigate, interact with elements, and assert page state.
Example
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
# Selenium Manager handles driver automatically
driver = webdriver.Chrome()
try:
driver.get('https://www.google.com')
search_box = driver.find_element(By.NAME, 'q')
search_box.send_keys('Selenium WebDriver')
search_box.send_keys(Keys.RETURN)
results = driver.find_elements(By.CSS_SELECTOR, 'h3')
assert len(results) > 0, 'No search results found'
print(f'Found {len(results)} results')
finally:
driver.quit()
Related on TokRepo
- AI tools for testing — Other testing frameworks and AI-assisted test generation tools.
- AI tools for browser automation — Compare Selenium with modern browser automation alternatives.
Common pitfalls
- Not using explicit waits. Elements may not be immediately available after page load; use WebDriverWait instead of sleep().
- Hardcoding driver paths. Use Selenium Manager or a driver management library to keep drivers in sync with browser versions.
- Writing brittle selectors. Prefer data-testid attributes or stable CSS selectors over XPath expressions that break with layout changes.
常见问题
Selenium is the original browser automation tool with the widest language support and ecosystem. Playwright is newer, offers built-in auto-waiting and better parallel execution, but supports fewer languages. Selenium has more community resources and third-party integrations.
Yes. All modern browsers support headless mode through Selenium. Add the --headless argument to your browser options to run tests without a visible browser window, which is common in CI environments.
Selenium has official client libraries for Java, Python, C#, Ruby, and JavaScript. Community-maintained bindings exist for other languages like Go and Kotlin.
Yes. Selenium remains the most widely used browser automation framework. Its W3C WebDriver protocol is the standard that other tools build on. The ecosystem of plugins, grid infrastructure, and CI integrations is unmatched.
Selenium itself is for web browsers. For mobile app testing, Appium extends the WebDriver protocol to iOS and Android. Selenium tests for mobile web (browser on phone) work through remote WebDriver with mobile device emulation.
引用来源 (3)
- Selenium GitHub— Selenium is the industry standard for browser automation
- W3C WebDriver Spec— WebDriver is a W3C standard
- Selenium Docs— Selenium documentation and API reference
讨论
相关资产
Docker Selenium Grid — Containerized Browser Testing at Scale
Docker Selenium provides pre-built container images to run Selenium Grid with Chrome, Firefox, and Edge, enabling scalable browser automation in CI/CD pipelines.
WXT — Next-Gen Framework for Browser Extension Development
A TypeScript-first framework for building cross-browser extensions with hot reload, auto-imports, and built-in support for Chrome, Firefox, Safari, and Edge from a single codebase.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.
Textual — Rapid Application Development Framework for the Terminal
Textual is a Python framework for building sophisticated TUI applications with CSS-based styling, async event handling, and 20+ built-in widgets. The same app can run in the terminal or in a web browser.