How to install and configure Selenium for Python (drivers, versions, and tips)
Informational article in the Automation for QA: Selenium, Playwright & CI Integration topical map — Getting Started: Setup & First Tests content group. 12 copy-paste AI prompts for ChatGPT, Claude & Gemini covering SEO outline, body writing, meta tags, internal links, and Twitter/X & LinkedIn posts.
How to install and configure Selenium for Python (drivers, versions, and tips) requires installing the Selenium package with pip (pip install selenium), obtaining the matching browser WebDriver binary (for example chromedriver for Chrome or geckodriver for Firefox where the driver major version matches the browser major version), and pinning Selenium, browser, and driver versions so that automated tests do not fail with "session not created" errors. The Selenium client implements the W3C WebDriver protocol and recent Selenium releases include Selenium Manager to help locate and launch compatible drivers.
The mechanism relies on the WebDriver protocol as the transport layer: Selenium sends JSON-over-HTTP commands to a browser-specific driver process which then controls the browser engine. Tools such as Selenium Manager and the Python package webdriver-manager automate discovery and download of binaries, while pip install selenium provides the Python bindings that speak the protocol. For headless chrome selenium use cases, Chrome or Chromium can be launched with --headless and appropriate flags; CI runners often require additional OS packages to run headless browsers reliably. This article focuses on selenium webdriver python patterns for local and CI environments.
The important nuance is that automatic driver resolution is not fail-safe: many teams encounter selenium version compatibility problems when a CI image or developer machine auto-updates the browser. A concrete scenario is a GitHub Actions runner that updates Chrome to a new major release while chromedriver remains pinned, producing "session not created" errors; pinning both the browser and chromedriver or using webdriver-manager as a controlled fallback prevents that. Another frequent mistake is relying solely on Selenium Manager in CI without installing OS dependencies (for example missing libraries on Debian slim or Alpine), or installing selenium drivers chrome geckodriver globally without documenting PATH, which leads to environment-specific failures despite pip install selenium succeeding.
Practically, install with pip install selenium into a virtual environment, choose either Selenium Manager or webdriver-manager for driver lifecycle, and pin versions in requirements files and CI manifests; include simple smoke tests that start a headless browser to validate the chain. Teams can also use official browser Docker images that bundle matching drivers to reduce drift. This page provides a structured, step-by-step framework for installation, driver management, version compatibility checks, and common CI troubleshooting.
- Work through prompts in order — each builds on the last.
- Click any prompt card to expand it, then click Copy Prompt.
- Paste into Claude, ChatGPT, or any AI chat. No editing needed.
- For prompts marked "paste prior output", paste the AI response from the previous step first.
install selenium python
How to install and configure Selenium for Python (drivers, versions, and tips)
authoritative, practical, step-by-step
Getting Started: Setup & First Tests
QA engineers and Python developers with beginner-to-intermediate knowledge who need a reliable, production-ready Selenium setup for local development and CI
A concise hands-on install + compatibility matrix that covers Selenium versions, browser driver management (including Selenium Manager and webdriver-manager), CI installation steps, troubleshooting tips, and practical commands so readers can finish setup and run their first test without guesswork.
- selenium webdriver python
- selenium drivers chrome geckodriver
- selenium version compatibility
- pip install selenium
- Selenium Manager
- headless chrome selenium
- Not pinning a compatible Selenium and browser driver version, causing 'session not created' errors when the browser updates.
- Assuming Selenium Manager will always work in CI; many CI runners need additional packages or a fallback driver install.
- Installing drivers globally without documenting paths or adding webdriver-manager, leading to environment-specific failures.
- Skipping a virtual environment or pinning dependencies, which produces inconsistent test runs across machines and CI.
- Ignoring headless vs headed differences and failing to include browser flags required for headless CI environments.
- Using outdated Selenium 3.x code patterns instead of Selenium 4 WebDriver W3C-compliant APIs.
- Not verifying driver and browser versions with explicit commands in the README or CI pipeline, so debugging takes longer.
- Pin both Selenium and browser-driver versions in requirements.txt (example: selenium==4.10.0) and include a one-line comment describing compatible browser versions.
- Prefer Selenium Manager or webdriver-manager for local development, but add explicit driver install steps in CI YAML so builds remain reproducible.
- Provide a small compatibility matrix in the article listing Selenium version, Chrome version range, ChromeDriver release, and GeckoDriver mapping—readers use it as a quick reference.
- Include a minimal Dockerfile or reference to a Selenium Grid Docker image for teams that want consistent browser environments across CI and local runs.
- Add explicit verification commands (python -c 'import selenium; print(selenium.__version__)' and chrome --version or geckodriver --version) and show expected output for quick troubleshooting.
- Show a sample GitHub Actions job snippet that installs drivers using apt or uses Selenium Manager, runs tests, and caches drivers to speed up CI.
- Recommend using headless flags plus --no-sandbox and --disable-dev-shm-usage for Linux CI environments and explain why each flag is needed.
- Document common error messages and exact commands to collect logs (browser console logs, Selenium logs) — this reduces time to diagnose flaky tests.