How to Use Selenium Stealth Mode to Bypass Bot Detection

Jacob Muganda

Posted On: September 3, 2025

11 Min

Web scraping is a crucial technique for extracting data from websites, but many sites deploy anti-bot measures that can block standard automation tools like Selenium. Selenium Stealth Mode helps make automated browsers appear more like real users by adjusting browser behavior, reducing the chances of detection and enabling more reliable data extraction.

Overview

What is Selenium Stealth Mode?

Selenium Stealth Mode simulates real user behavior to help automation avoid bot detection. It also adapts easily to different website security checks.

Key features of Selenium Stealth Mode

  • Mask Automation: Hides navigator.webdriver and other detectable properties.
  • Realistic Browsing: Spoofs headers, user-agent, and platform info.
  • Human-Like Behavior: Adds delays, scrolling, and click patterns.
  • Cloud & Local Ready: Works seamlessly across environments and Selenium grids.

Steps to Run Selenium Stealth Mode for Anti-Bot Bypass

  • Set up environment: Initialize a Python virtual environment for isolated testing.
  • Install dependencies: Add Selenium, Selenium Stealth, WebDriver Manager, and dotenv.
  • Configure ChromeDriver: Apply Chrome options to handle sandboxing and system resources.
  • Enable stealth Mode: Mask automation flags, headers, WebGL, and platform info.
  • Navigate and interact: Open the target site, wait for elements, and simulate user actions.
  • Verify stealth: Check page title, user agent, and WebDriver detection status.
  • Handle exceptions: Catch and log errors for debugging.
  • Close browser: End session and free system resources.

Steps to Run Selenium Stealth Mode on Cloud

  • Set up credentials: Create a .env file and add your LambdaTest username and access key.
  • Configure capabilities: Define browser, OS, and other automation settings for your test.
  • Connect to LambdaTest Selenium Grid: Link your local script to the cloud infrastructure.
  • Run your tests: Execute Selenium Stealth Mode scripts, verify stealth functionality, and interact with elements as usual.

What Is Selenium Stealth Mode?

Selenium Stealth Mode is a Python library that modifies browser properties to prevent detection by anti-bot systems when using Selenium WebDriver. It tweaks automation indicators, like the navigator.webdriver flag and certain browser fingerprints, by adjusting JavaScript properties, headers, and interaction patterns.

The library is lightweight and integrates easily into existing Selenium scripts, helping you scrape or automate protected websites with a lower risk of detection. For a broader understanding of Selenium’s features and usage, you can also follow this Selenium tutorial.

Key Benefits of Using Selenium Stealth Mode

Using Selenium Stealth Mode provides significant advantages for web scraping operations, particularly when dealing with protected websites and sophisticated anti-bot systems.

  • Modify browser behavior: Adjusts browser properties and JavaScript variables to mimic human-like interactions.
  • Conceal automation signatures: Tweaks indicators like navigator.webdriver and other detectable patterns.
  • Easy integration: Works seamlessly with existing Selenium scripts with minimal code changes.

Running Selenium Stealth Mode for Anti-Bot Bypass

Let’s implement Selenium Stealth Mode through practical examples, starting with environment setup and progressing through local to cloud-based implementations.

Environment Setup:
First, create a virtual environment and install the required packages, using the following commands below:

Now that all the required packages are installed, let’s consider a simple test scenario to understand how Selenium Stealth Mode works.

Test Scenario

  1. Launch the Chrome browser with Stealth Mode enabled.
  2. Open the LambdaTest Selenium Playground page.
  3. Verify that stealth Mode is applied by checking the page title, WebDriver detection, and User Agent.
  4. Wait for the input field to be present on the page.
  5. Print success messages for verification.
  6. Close the web browser.

Code Implementation:

Now let’s implement the given test scenario:

Code Walkthrough:

  1. Calling webdriver.Chrome(): Main thread pushes the Chrome WebDriver creation onto the stack; the browser starts with the given Chrome options (–no-sandbox, –disable-dev-shm-usage).
  2. Nested Function stealth(driver, …): The WebDriver instance calls stealth(), which is pushed onto the stack; it modifies browser properties such as navigator.webdriver, user agent, platform, vendor, and WebGL renderer to appear human-like. The main thread waits while these changes apply.
  3. Calling driver.get(URL): The main thread pushes the get() call onto the stack to navigate to the LambdaTest Playground page; execution pauses until the page fully loads.
  4. Nested Function driver.title: The WebDriver retrieves the page title; this call is pushed onto the stack, executed, and popped once the title is returned.
  5. Nested Functions driver.execute_script(…):
    • navigator.webdriver check is pushed to the stack and executed to verify Stealth Mode.
    • navigator.userAgent retrieval is pushed to the stack and executed to confirm the modified User Agent.
  6. Nested Function WebDriverWait(driver, 10): Main thread pushes the wait setup onto the stack to monitor the page for elements.
  7. Nested Function wait.until(EC.presence_of_element_located((By.TAG_NAME, “input”))): The wait object calls until(), pushed onto the stack; execution pauses until the input element is found.
  8. Calling print() statements: Each print command is pushed onto the stack sequentially to display the page title, WebDriver detection status, user agent, and test completion message, then popped after execution.
  9. Nested Function except Exception as e: If any error occurs, the exception block is pushed onto the stack; the error message is printed, and the block is popped.
  10. Calling driver.quit(): The main thread pushes quit() onto the stack; the browser closes and resources are freed, then the call is popped.

Test Execution:

To Execute the code run the following command:

selenium-stealth-mode-local

Running Selenium Stealth Mode locally can often be challenging for testers and developers. Differences in browser versions, limited system resources, IP-based restrictions, and inconsistent environments can make stealth automation unreliable and difficult to scale. These issues may sometimes result in detection or script failures.

In such situations, cloud-based Selenium automation offers a more reliable approach. Platforms like LambdaTest provide consistent browser and OS environments, enable parallel test execution, and give access to geographically distributed IPs for enhanced stability and scalability.

This setup can make Selenium Stealth properties more stable across different configurations, while also providing real browser instances with monitoring and debugging tools, supporting smoother and more manageable automation workflows.

Key takeaway: Local stealth setups work but are fragile across environments. Cloud Selenium grids provide more consistent results.

Running Selenium Stealth Mode on Cloud Selenium Infrastructure

Executing Selenium Stealth Mode on cloud-based platform like LambdaTest allows you to perform Selenium automation testing without worrying about local system limitations or environment inconsistencies.

With LambdaTest, you can scale your tests across multiple browsers and OS combinations effortlessly, while also gaining access to detailed logs and real-time debugging tools for improved test reliability.

LambdaTest is a GenAI-native test execution platform that allows you to perform manual and automated tests on a Selenium Grid online at scale across 3000+ browser and OS combinations. It helps you maintain consistency while minimizing detection risks and environment issues, even in Stealth Mode.

To get started with Selenium Stealth Mode on LambdaTest, all you need to do is follow the instructions below.

  1. Create .env file: Securely store your LambdaTest credentials, create a .env file in the root of your project and add the following values:

  2. Get LambdaTest Credentials: You can find these credentials under Account Settings > Password & Security and copy your Username and Access Key, then add them to the .env file to keep them safe from public exposure.
  3. Connect LambdaTest: Update your test script to use these variables when connecting to the LambdaTest Selenium Grid URL.

  4. Get LambdaTest Capabilities: Next, set up the LambdaTest capabilities to define key automation testing parameters, such as browser, version, operating system, and additional test settings. These capabilities ensure your tests run in the exact environment you need, as shown below:

You can generate the necessary Selenium Stealth Mode capabilities using LambdaTest Automation Capabilities Generator.

Running your Stealth Mode tests on LambdaTest’s cloud infrastructure removes the need to manage local environments, while support for parallel execution allows you to scale efficiently, reduce test times, and run reliable anti-bot automation with minimal setup.

For more details, check out the documentation on running Selenium Automation Testing Using LambdaTest.

Finally, combine cloud execution with Selenium Stealth Mode capabilities.

This code highlights the shift from basic Selenium setups to a cloud-based stealth Mode implementation, showing how each step overcomes different scraping challenges.

Test Execution:

You can review the session details directly in the LambdaTest Automate dashboard, as shown in the screenshot below.

Lambdatest-exeution

Stealth Mode Techniques to Avoid Detection

Selenium Stealth Mode employs multiple sophisticated techniques to mask automation signatures and avoid detection by anti-bot systems. Understanding these techniques helps optimize your scraping implementation.

  • WebDriver Property Masking: The most fundamental detection method involves checking the navigator.webdriver property. Stealth Mode disables this flag:
    This removes the primary indicator that reveals automated Selenium ChromeDriver sessions, making them resemble normal browsing.
  • User-Agent and Header Modification: Anti-bot systems analyze request headers for consistency and legitimacy. Stealth Mode configures realistic browser attributes:
    These parameters ensure headers match typical user configurations rather than default automation values. (Without this, Selenium often exposes generic values that detection systems can easily flag.)
  • Browser Fingerprinting Protection: Modern detection systems create unique browser fingerprints using WebGL and canvas properties. Stealth Mode masks these identifiers:
    This prevents websites from building unique device profiles that could identify repeat visits from the same automation script. (For example, canvas fingerprinting generates hashes that normally stay consistent across visits; masking randomizes these.)
  • Behavioral Pattern Simulation: Beyond technical masking, effective stealth requires realistic interaction patterns:

    These patterns make automation less distinguishable from genuine user behavior. Instead of executing commands instantly (which no human does), small delays and simulated scrolling/clicking mimic normal browsing.

  • According to Cloudflare’s bot management documentation, modern detection often relies on behavioral analysis beyond browser fingerprints. Independent research from Distil Networks highlights how bots are identified through request velocity and anomaly detection. This setup helps you avoid most common detection methods while still working smoothly on most websites.

    Ethics and Legal Aspects of Selenium Stealth Mode

    Web scraping with stealth capabilities requires careful attention to ethical and legal considerations. Responsible scraping practices protect both your projects and the websites you’re accessing.

    • Respect Website Terms of Service: Always review and comply with website terms of service before implementing any scraping solution. Many sites explicitly prohibit automated access, and violating these terms can result in legal consequences regardless of your technical approach.
    • Follow robots.txt Guidelines: Check the website’s robots.txt file to understand which areas are off-limits to automated tools:
    • Implement Rate Limiting: Avoid overwhelming servers with rapid requests. Implement delays and respect server resources:

    Remember that stealth capabilities should enhance legitimate scraping operations, not enable malicious or unauthorized data collection.

    Beyond legality, scraping responsibly helps preserve site performance. Industry standards, such as the Internet Engineering Task Force (IETF) guidelines for automated web agents, emphasize respecting robots.txt, limiting request rates, and ensuring fairness in resource usage.

    Limitations of Selenium Stealth and Alternatives

    Selenium Stealth Mode offers powerful advantages in bypassing common anti-bot mechanisms, but it comes with trade-offs that developers must consider.

    Limitations of Selenium Stealth Mode:

    • Relies on Chrome only, limiting other browser compatibility.
    • Performance overhead slows large‑scale scraping jobs.
    • Requires frequent updates, increasing maintenance effort.
    • Fails against machine‑learning detection analyzing behavior.

    Alternative and Complementary Solutions:

    • Undetected ChromeDriver and Puppeteer stealth plugins.
    • Managed services handle proxies, CAPTCHA, and fingerprint evasion.
    • Official APIs provide reliable, compliant, rate‑limited data access.
    • Layered strategies combine proxies, timing, and varied tools.

    Ultimately, the best approach depends on factors like target site complexity, data volume, team expertise, and budget, often requiring a layered solution that combines stealth with proxy rotation, smart timing, or browser automation alternatives.

    Undetected ChromeDriver vs. Selenium Stealth

    The table contrasts two approaches for stealthy browser automation:

    Aspect Undetected ChromeDriver Selenium Stealth
    Installation pip install undetected-chromedriver pip install selenium-stealth
    Driver Initialization uc.Chrome() webdriver.Chrome() + stealth() call
    Evasion Method Uses a patched ChromeDriver binary to bypass checks Modifies session parameters (user agent, WebRTC, etc.)
    Code Changes Required Swap webdriver.Chrome() → uc.Chrome() only Keep webdriver.Chrome() and add explicit stealth calls
    Configuration Effort Minimal, handled internally Manual, must set each stealth parameter yourself
    Browser Support Chrome only Any browser supported by Selenium
    Out-of-the-Box Evasion High, many flags pre-configured Moderate, depends on how many parameters you tweak
    Portability Limited to Chrome Easily portable across browsers
    Ease of Use Very easy to get started Requires more setup and understanding of options

    Playwright also offers a stealth plugin via community packages, which applies similar browser property masking. While not as lightweight as Selenium Stealth, it integrates well with modern async scraping workflows, making it worth evaluating for Node.js-based teams.

    Conclusion

    Selenium Stealth Mode provides a powerful solution for bypassing anti-bot detection systems in web scraping applications. By modifying browser properties and masking automation signatures, it enables access to protected websites while maintaining the familiar Selenium WebDriver interface.

    The implementation progresses from local environments to cloud-based solutions, offering scalability for enterprise-level data extraction operations. However, success with stealth Mode requires understanding its limitations, implementing ethical scraping practices, and choosing appropriate alternatives when necessary.
    As anti-bot systems continue evolving, staying informed about detection methods and countermeasures remains essential for effective web scraping strategies.

    Frequently Asked Questions (FAQs)

    What is the difference between selenium-stealth and undetected-chromedriver?

    Selenium-stealth modifies browser properties after initialization, while undetected-chromedriver patches the ChromeDriver binary directly. Undetected-chromedriver is often more effective but less configurable than selenium-stealth.

    Can I use Selenium Stealth Mode with cloud testing platforms?

    Yes, Selenium Stealth Mode works with cloud platforms like LambdaTest. Apply stealth configuration after initializing the remote WebDriver connection for effective anti-detection in cloud environments.

    Does Selenium Stealth Mode work with all browsers?

    Selenium Stealth Mode is primarily designed for Chrome-based browsers. Firefox and Safari support is limited, so Chrome or Chromium browsers provide the best compatibility and effectiveness.

    How do I handle websites that still detect my stealth-enabled scripts?

    Combine stealth mode with additional techniques like proxy rotation, realistic interaction delays, and user-agent variation. Some advanced detection systems may require more sophisticated countermeasures or alternative approaches.

    Is using Selenium Stealth Mode legal for web scraping?

    The legality depends on the website’s terms of service, local laws, and how you use the collected data. Always review terms of service, respect robots.txt files, and ensure compliance with applicable regulations.

    Can I use Selenium Stealth Mode with headless browsers?

    Yes, but detection risk increases in headless mode. To improve stealth, mimic real browser behavior by adding arguments like –disable-blink-features=AutomationControlled and simulating human-like interactions.

    Does Selenium Stealth Mode impact browser performance?

    Slightly. Modifying browser fingerprints and behaviors can add overhead, but it’s generally minimal and outweighed by the benefit of reduced detection.

    How do I keep Selenium Stealth Mode updated with browser changes?

    Monitor updates to Chrome/Chromium and the stealth libraries. Frequent adjustments are necessary, since detection techniques evolve as browsers and anti-bot systems update.

    Can Selenium Stealth Mode bypass CAPTCHA challenges?

    Not directly. Stealth reduces bot detection but doesn’t solve CAPTCHA. You’ll need third-party CAPTCHA-solving services or custom machine learning solutions for automation.

    Is it possible to combine Selenium Stealth with Puppeteer or Playwright?

    Yes, but not directly in the same script. Some teams use Selenium Stealth for initial navigation and Puppeteer/Playwright for sections requiring stronger stealth, depending on project needs.

    Citations

Author

Jacob Muganda is a Community Contributor, currently works as a Software & AI Developer at the Export Processing Zones Authority (EPZA), Kenya. He has over four years of experience in test automation and quality assurance, with hands-on expertise in Selenium, Playwright, and Cypress. Jacob builds AI-driven apps and test suites powered by LLMs, Agentic Architectures, and RAG. At EPZA, he leads automation projects from execution to architectural design, using Jenkins, Docker/Kubernetes, CI/CD stacks, Next.js, Django, Python, and JavaScript/TypeScript. He has evolved from rapidly scripting tests to designing scalable AI-powered frameworks with continuous feedback. Jacob won the EFH AI Hackathon 2025 at iHub Nairobi and was Runner-Up at the Davis & Shirtliff Hackathon. He also holds Huawei HCIA certifications in AI and Cloud and is a certified Twilio Technical Writer.

Blogs: 1

linkedintwitter