Selenium Stealth is a Python library that patches Selenium WebDriver to make automated Chrome sessions look more like a real human user. It hides the telltale signs that a browser is automated, such as the “Chrome is being controlled by automated test software” banner and the navigator.webdriver property. This guide walks you through installing it, wiring it into a Selenium script, and verifying that your session passes basic bot-detection checks.
What You’ll Need
- Python 3.7 or newer installed on your system
- Google Chrome browser installed (the latest stable version)
- ChromeDriver matching your Chrome version (or let Selenium Manager handle it automatically with Selenium 4.6+)
- Basic familiarity with running Python scripts and installing packages via pip
Step-by-Step
- Create and activate a virtual environment (recommended)
Open a terminal and run:python -m venv venv. Then activate it: on Windows usevenv\Scripts\activate, on macOS/Linux usesource venv/bin/activate. This keeps dependencies isolated. - Install the required packages
Runpip install selenium selenium-stealth. If you are on Selenium 4.6 or later, you do not need to manually download ChromeDriver—Selenium Manager fetches it automatically. For older Selenium versions, download ChromeDriver from the official site and place it in your PATH. - Set up the Chrome options
In your Python script, importwebdriverandOptionsfrom selenium. Create anOptionsinstance and add common arguments to reduce automation fingerprints:options = Options()options.add_argument("--disable-blink-features=AutomationControlled")options.add_argument("--disable-infobars")options.add_argument("--start-maximized")
These hide the infobar and disable the Blink automation flag. - Create the WebDriver instance
Instantiate the driver:driver = webdriver.Chrome(options=options). At this point, you have a standard Selenium session, but it is still detectable. - Apply Selenium Stealth
Import the stealth module and patch the driver:from selenium_stealth import stealthstealth(driver,languages=["en-US", "en"],vendor="Google Inc.",platform="Win32",webgl_vendor="Intel Inc.",renderer="Intel Iris OpenGL Engine",fix_hairline=True,run_on_insecure_origins=False)
These parameters override JavaScript properties likenavigator.vendor,navigator.platform, and WebGL renderer strings, making the browser appear more like a genuine user’s Chrome. - Navigate and test
Use the driver normally:driver.get("https://example.com"). To verify stealth is working, execute a JavaScript snippet that checks for automation markers:print(driver.execute_script("return navigator.webdriver"))
It should printNone(orundefined) instead ofTrue. You can also checknavigator.plugins.length—it should be greater than 0, whereas a default Selenium session often shows 0. - Run your automation script
Proceed with your scraping or testing logic. Keep the session alive and close it properly at the end:driver.quit().
Common Mistakes
- Applying stealth before creating the driver—The
stealth()function must be called on an existing WebDriver instance, not before it. - Forgetting to disable the automation-controlled flag—Without
--disable-blink-features=AutomationControlled, thenavigator.webdriverproperty remains true even after stealth is applied. - Using an outdated ChromeDriver—Version mismatches between Chrome and ChromeDriver cause session errors that have nothing to do with stealth.
- Overlooking the virtual environment—Installing packages globally can lead to conflicts with other projects or system Python packages.
- Expecting complete invisibility—Stealth reduces detection but does not guarantee you will pass every anti-bot system. Some sites use advanced behavioral analysis that no library can fully bypass.
Tips
- Use a real user agent string by removing the default one and letting Chrome set it naturally, or set a current one manually via
options.add_argument("--user-agent=..."). - Add random delays between actions (
time.sleep(random.uniform(1, 3))) to mimic human pacing. - Run Chrome with a real profile directory using
options.add_argument("--user-data-dir=/path/to/profile")to retain cookies and site preferences, which makes the session look more established. - Test your stealth setup against a detection test page (like the one at bot.sannysoft.com) to see which properties are still exposed.
- Keep the stealth library updated—it is actively maintained to keep up with Chrome changes.
Troubleshooting
- “selenium-stealth not found” error—Make sure you installed it in the same virtual environment where you are running your script. Re-run
pip install selenium-stealth. - ChromeDriver binary location error—If Selenium cannot find ChromeDriver, either add its directory to your PATH or specify the path explicitly:
webdriver.Chrome(executable_path="/path/to/chromedriver", options=options). - The stealth patch throws an AttributeError—This usually means you are using an incompatible Selenium version. Upgrade Selenium to the latest:
pip install --upgrade selenium. - Site still detects automation—Check the console for other exposed properties like
window.chromebeing undefined. You can patch it manually withdriver.execute_script("window.chrome = { runtime: {} };"). - Chrome crashes on startup—Try removing the
--start-maximizedargument or adding--no-sandbox(Linux only) and--disable-dev-shm-usageif you are in a container. - Pages load slowly or time out—Stealth adds extra JavaScript execution. Increase your implicit wait or use explicit waits with
WebDriverWait.
Frequently Asked Questions
Does Selenium Stealth work with undetected-chromedriver?
They serve different purposes. Undetected-chromedriver patches the driver binary itself, while stealth patches the JavaScript environment. You can use them together, but it is usually unnecessary—stealth alone is sufficient for most sites.
Will this work with headless Chrome?
Yes, but headless mode is easier to detect because it lacks certain visual features. If you must use headless, add --headless=new (Chrome 109+) and test carefully. For maximum stealth, run headed mode in the background.
Is using Selenium Stealth legal?
It depends on the website’s terms of service and your jurisdiction. Automating interactions may violate a site’s ToS. Always check the site’s rules and applicable laws before scraping or automating.
Can I use stealth with Firefox or Edge?
The selenium-stealth library is designed for Chrome only. For Firefox, consider using the selenium-wire library or manual JavaScript patching. Edge (Chromium-based) may work with some tweaks, but it is not officially supported.
How often should I update the stealth parameters?
Update the library whenever Chrome releases a major version. The default parameters are fine for most cases, but if a site starts detecting you, revisit the webgl_vendor and renderer values to match your actual graphics hardware.
Does stealth slow down my scripts?
Minimally. The patch runs once at startup and adds negligible overhead. The bigger performance impact comes from the human-like delays you add yourself, which are necessary to avoid detection.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- Voice Dictation in Google Docs: How to Use It
- Turn Off Message Notifications on Mac