Registry / testing / selenium-stealth

selenium-stealth

JSON →
library1.0.6pypypi✓ verified 85d ago

Selenium Stealth is a Python library designed to make Selenium WebDriver more stealthy, aiming to bypass anti-bot detection systems on websites. It achieves this by modifying various browser properties and behaviors that typically reveal automated browsing, such as the `navigator.webdriver` flag, user-agent, and WebGL fingerprints. The library currently supports Chrome/Chromium and is at version 1.0.6. While still functional for many use cases, its last update on PyPI was in November 2020, and there is an actively maintained fork, `stealthenium`, for those seeking ongoing development.

pip install selenium-stealth
INSTALL
IMPORT
SIG · SELENIUM-STEALTH
S
selenium-stealth
testingpythonv1.0.6
Install
3.6s avg
Import
695ms
Disk
53MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.726s · 53.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.6s · import 0.665s · 54MB
53MB installed
● package 53MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stealth
from selenium_stealth import stealth

This quickstart initializes a Chrome WebDriver instance with common options to hide automation indicators, then applies the `selenium-stealth` modifications. It navigates to a known bot detection test site (`sannysoft.com`) to demonstrate its effect. Ensure you have `chromedriver` compatible with your Chrome browser version, either in your system PATH or specified via `Service(executable_path=...)`.

from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from selenium_stealth import stealth import time # Set up Chrome options chrome_options = Options() chrome_options.add_argument("start-maximized") chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_options.add_experimental_option('useAutomationExtension', False) # Configure ChromeDriver service (optional for Selenium 4.6+ if Chrome is in PATH) # If ChromeDriver is not in PATH, uncomment and set executable_path # service = Service(executable_path='/path/to/chromedriver') # driver = webdriver.Chrome(service=service, options=chrome_options) # For Selenium 4.6+ and Chrome in PATH, direct initialization is often sufficient driver = webdriver.Chrome(options=chrome_options) # Apply stealth settings stealth( driver, languages=["en-US", "en"], vendor="Google Inc.", platform="Win32", webgl_vendor="Intel Inc.", renderer="Intel Iris OpenGL Engine", fix_hairline=True, ) print("Navigating to a test site...") driver.get("https://bot.sannysoft.com/") # A common site to test bot detection time.sleep(5) # Give some time for the page to load and scripts to run print(f"Page title: {driver.title}") # Add your scraping logic here driver.quit() print("Browser closed.")
Debug
Known issues
deprecatedThe `selenium-stealth` project has not received updates on PyPI since November 2020 and its maintenance status is considered inactive. A more actively maintained fork, `stealthenium`, is available and explicitly states it's a fork of this unmaintained project. Consider migrating to `stealthenium` for ongoing support and updates.
fix
Consider `pip install stealthenium` and updating your imports and usage according to its documentation.
affects: <=1.0.6
gotchaSelenium Stealth currently only supports Chrome/Chromium browsers. It does not provide stealth capabilities for Firefox, Edge, or other browsers.
fix
Ensure you are using `selenium.webdriver.Chrome` with compatible Chrome browser and ChromeDriver versions.
affects: *
gotchaWhile `selenium-stealth` enhances anonymity, running browsers in headless mode (`--headless` Chrome option) can still be a strong indicator of automation and may lead to detection on sophisticated anti-bot sites.
fix
For highly resistant websites, consider running in headful mode (without `--headless`), adding realistic delays (`time.sleep()`), simulating mouse movements, and using rotating proxies.
affects: *
gotchaAttempting to manually spoof browser properties like `User-Agent` via Chrome options without ensuring consistency with other `navigator` properties (e.g., `platform`) can lead to immediate bot detection. `selenium-stealth` handles many of these internally.
fix
Rely on `selenium-stealth`'s default parameter values, or be extremely careful when customizing parameters like `languages`, `vendor`, `platform`, `webgl_vendor`, and `renderer` to ensure they form a consistent, realistic browser fingerprint.
affects: *
Errors
Common errors & fixes
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: DevToolsActivePort file doesn't exist
This typically indicates an incompatibility between your Chrome browser version and the ChromeDriver executable version, or issues with Chrome launching (e.g., insufficient memory, corrupted user profile, or sandbox issues in Docker).
fix
Update your ChromeDriver to match your Chrome browser version. Check `chrome://settings/help` for your Chrome version, then download the corresponding ChromeDriver from the official site. Also, ensure sufficient system resources and add `--no-sandbox` if running in a containerized environment.
Websites are still detecting my Selenium script as a bot, despite using selenium-stealth.
While `selenium-stealth` addresses many common detection vectors (like `navigator.webdriver`), advanced anti-bot systems employ more sophisticated techniques, including analyzing behavior patterns (speed, mouse movements), IP reputation, CAPTCHA challenges, and complex browser fingerprinting beyond what `selenium-stealth` alone can spoof.
fix
Beyond `selenium-stealth`, consider: 1) Using `undetected_chromedriver` (a separate project designed for this purpose). 2) Adding random delays (`time.sleep()`) and simulating human-like interactions (scrolls, mouse movements). 3) Rotating IP addresses with proxies. 4) Avoiding headless mode or configuring it very carefully. 5) Maintaining browser profiles (cookies) to build 'trust'.
I get inconsistent results or elements not found when rapidly interacting with a page after applying stealth.
Even with stealth, rapid, robotic interactions or failure to wait for dynamic content to load can trigger anti-bot measures or simply cause race conditions in your script. Websites expect human-like interaction speeds.
fix
Implement `time.sleep()` for random delays between actions. Use Selenium's explicit waits (`WebDriverWait` and `expected_conditions`) to ensure elements are present, visible, and clickable before interacting with them. Mimic human scrolling behavior.
Upgrade
Version history
1.0.6latest on PyPI · released Nov 5, 2020
Audit
Dependencies
seleniumrequiredRequired for browser automation.
Agent activity
25 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources