How to handle Captcha in Selenium

Related Product On This Page What is Captcha?Likely Test

June 17, 2026 · 9 min read · Tool Comparison
Related Product

How to cover Captcha in Selenium

As technology has become plant in today ’ s world, digital security has be a major care and for full reason. Hackers use bots to operate web applications and access data such as user e-mail addresses that lead to spamming, posing threats to privacy.

A measure to prevent such bot activity is to use Captcha (Completely Automated Public Turing test to tell Computers and Humans Apart). It is rather commonly used, which is why testers much search for means to examine Captcha via Selenium.

For examiner seeking tips on testing “ Selenium Captcha ”, “ Selenium ReCaptcha ” and wondering “ how to handle captcha in selenium ”, this article will facilitate. It will discuss how Captcha can be tested via by QA engineer.

Read More:

What is Captcha?

Through Captcha, the user is asked to perform a sure task, such as enter the schoolbook written in the image or click on the images from a set of different ikon that match the mandatory criteria.

These tasks are meant to ascertain whether the user is a human or a bot. Since the task is dynamic, it can exclusively successfully be carried out with human cognizance and correct interpretation of information & # 8211; region where the artificial intelligence of bots tends to betray.

Some variants of Captcha besides support visually impaired individuals by generating audio alternatively of images.

Google ’ s open-source CAPTCHA widget, reCAPTCHA is widely habituate, since it supports major screen reader such as JAWS and NVDA for IE, Edge, or Chrome on Windows OS, ChromeVox for Chrome OS, and VoiceOver for Safari and Chrome on Mac OS.

Likely Test Cases around Captcha

Here are some potential around captcha:

Cases:

  • Verify CAPTCHA look on the intended forms/pages like login, sign-up, password reset, and contact pattern.
  • Verify CAPTCHA is postulate before form compliance.
  • Verify compensate CAPTCHA entry allows pattern entry

Cases: 

  • Verify third-party CAPTCHA services (like Google reCAPTCHA) are right integrated.
  • Verify that website and CAPTCHA integration grip API/network mistake properly.

Cases

  • Verify CAPTCHA is responsive and show correctly on all screen sizes.
  • Verify CAPTCHA is accessible
  • Verify the image/audio CAPTCHA is open and legible.

Test Cases

  • Verify that the scheme cover the load if the CAPTCHA service goes downwardly.
  • Verify CAPTCHA doesn & # 8217; t significantly slow down page consignment multiplication.

Read More:

Handling Captcha Enabled Web Applications in Selenium

For web coating with Captcha enabled, could be an number, particularly as the step involving Captcha can create a preventative in a test scenario. Moreover, the idea of Captcha itself does not adjust with mechanization, as doing so will defeat the function of prohibiting bots from performing activities on the application.

Thus, it is crucial to efficiently handle Captcha in Selenium Testing to ascertain that tests run seamlessly without any bottlenecks.

While automating Captcha is not the best practice, there are three efficient ways ofhandling Captcha in Selenium:

  1. By disabling the Captcha in the examination environment
  2. Adding a hook to snap the Captcha checkbox
  3. By adding a postponement to the Webdriver and manually solve Captcha while testing

How to Disable Captcha in the Test Environment

Disabling Captcha in the would assure that while quiz a web coating, the Captcha task is not involve. While using Google ’ s open-source Captcha widget & # 8211; reCAPTCHA v2, put in theSite Key and the Secret Key, (known as the trial keys). As a effect, all verification requests will pass, and automated UI quiz can be conducted seamlessly.

  • Site key:6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
  • Secret key:6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe

However, while doing so, the reCAPTCHA widget will show a warning alert that ensures that the CAPTCHA is bypassed only for testing purposes and not in real-time entree by users.

In the case of reCAPTCHA v3, the user needs to create a freestanding key for prove environments. Unlike reCAPTCHA v2, which has a generic testing key to endorse, reCAPTCHA v3 requires creating freestanding keys for the testing environment. Users can create key for reCAPTCHA v3.

It is recommended tocreate one site keyper web or nomadic application. However, one can make separate website key for staging and production environments. This is because there is a hazard of contaminating reCAPTCHA hazard analysis with the data from the test surround, which might alter the event of the analysis.

Also Read:

How to chatter the checkbox in reCaptcha during Selenium testing

By adding a hook to the code, users can bypass the Captcha while execute. The Captcha recognizes a bot clicking the checkbox component by the fact that it takes less time for the bot to snap as compared to mankind. Therefore, examiner need to induce WebDriverWait, so that the element is clicked alone when it becomes clickable. This bypasses the Captcha.

Here ’ s thecodeto add a hook that clicks on reCAPTCHA employ Selenium and Java-

public form ReCaptcha_click {public motionless emptiness main (String [] args) {System.setProperty (`` webdriver.chrome.driver '', `` C: \\Utility\\BrowserDrivers\\chromedriver.exe ''); ChromeOptions options = new ChromeOptions (); options.addArguments (`` start-maximized ''); options.addArguments (`` disable-infobars ''); options.addArguments (`` -- disable-extensions ''); WebDriver driver = new ChromeDriver (options); driver.get (`` https: //rsps100.com/vote/760 ''); new WebDriverWait (driver, 10) .until (ExpectedConditions.frameToBeAvailableAndSwitchToIt (By.xpath (`` //iframe [starts-with (@ name, ' a- ') and starts-with (@ src, 'https: //www.google.com/recaptcha ')] ''))); new WebDriverWait (driver, 20) .until (ExpectedConditions.elementToBeClickable (By.cssSelector (`` div.recaptcha-checkbox-checkmark ''))) .click ();}}

Talk to an Expert

How to add delay and manually solve Captcha during Automation Testing

Firstly, this method is not completely automated and requires human intervention to solve the Captcha. Call it a semi-automated test.

In this method, a delay of 10-20s is enclose to freeze the captcha screen, so that the page does not suffer from the race precondition, which generally happens while using mechanisation testing on a web page with a Captcha element.

This is because automation testing is much quicker than the centering on reCAPTCHA. Thereby, the word is entered much before the reCAPTCHA component even gets ready, leading to.

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

By adding a wait to the testing, it ensures that by the time reCAPTCHA is ready, the form fill-up action waits and the racing condition can be elude tactfully, streamlining the test and make it more precise.

To delay execution of for 10 seconds expend Python, use the following command

import clip time.sleep (10)

Here ’ s how delay can be supply using Puppeteer for headless browsers:

const puppeteer = require ('puppeteer '); const chromeOptions = {headless: false, defaultViewport: null}; (async function main () {const browser = await puppeteer.launch (chromeOptions); const page = await browser.newPage (); await page.goto ('https: //old.reddit.com/login ');}) () expect page.type (' # user_reg ', 'some_username '); await page.type (' # passwd_reg ', 'SuperStrongP @ ssw0rd '); expect page.type (' # passwd2_reg ', 'SuperStrongP @ ssw0rd '); await page.click (' # register-form push [type=submit] '); const chromeOptions = {headless: false, defaultViewport: zilch, slowMo:15,};

Captcha, which has been an significant UI element to restrict bots from access a web covering, has posed a major challenge for the testers execute.

Read More:

Since automating Captcha would defeat the purpose of having Captcha in the first place to ensure human interaction with the UI, it is real tricky to treat Captcha in Selenium.

However, with the test keys and crotchet, it is potential to check that the Captcha does not halter. Captcha handling in Selenium is a mandatory skill of QAs because of how frequently Captcha is used as a protection measure.

How to Bypass CAPTCHA With SeleniumBase and Undetected ChromeDriver for Testing

Bypassing CAPTCHAs in automated testing can be challenging since they are designed to prevent bots like Selenium from interacting mechanically.

However, there are some ways to cover CAPTCHAs using puppet like SeleniumBase and Undetected ChromeDriver for testing purpose. Here ’ s how:

Step 1. Install Dependencies

Install Python and then:

pip install seleniumbase undetected-chromedriver

Step 2. Use Undetected ChromeDriver with SeleniumBase

Customize SeleniumBase to use Undetected ChromeDriver as the browser driver.

import undetected_chromedriver.v2 as uc from seleniumbase import BaseCase class MyTest (BaseCase): def setUp (self): # Initialize undetected chromedriver manually self.driver = uc.Chrome () # Inject driver to SeleniumBase 's BaseCase self._setup_driver (self.driver) def test_bypass_captcha (self): self.open (`` https: //your-testing-site.com '') # Your test step hither # Example: Fill login variety, click buttons, etc. # If CAPTCHA appears, you may: # - Wait for manual input # - Use a CAPTCHA-solving service API # - Bypass CAPTCHA in the examination environment by disabling it # Example: Wait for exploiter to solve CAPTCHA manually self.wait_for_element (`` input # captcha-response '', timeout=60)

Step 3. Handling CAPTCHA

  • Manual intervention:Pause the exam and let a examiner solve CAPTCHA during automated tryout performance.
  • CAPTCHA-solving services:Use APIs like 2Captcha, etc., where your book send CAPTCHA image to the service and retrieves the answer. This would postulate consolidation.
  • Disable CAPTCHA in:If you control the environment, disable CAPTCHA during machine-controlled tests.

Read More:

How to Handle Captcha with Selenium Stealth

Selenium Stealth is a Python package that modifies the browser ’ s JavaScript surround and demeanour to mask Selenium automation fingerprints that websites often detect and trigger CAPTCHAs.

Here ’ s how you can handle CAPTCHA with Selenium Stealth

Step 1: Install Selenium and Selenium Stealth

pip install selenium selenium-stealth

Step 2: Introductory Usage Example

from selenium import webdriver from selenium_stealth import stealth options = webdriver.ChromeOptions () # You can add options here, like headless mode, user agent, etc. driver = webdriver.Chrome (options=options) stealing (driver, languages= [`` en-US '', `` en ''], vendor= '' Google Inc. '', platform= '' Win32 '', webgl_vendor= '' Intel Inc. '', renderer= '' Intel Iris OpenGL Engine '', fix_hairline=True,) driver.get (`` https: //example.com '') # Your test action here driver.quit ()

This minimizes the risk of be flagged as a bot by hiding Selenium touch.

Why use BrowserStack Automate for Selenium Tests?

Here ’ s why you should use to run Selenium Tests:

  • : BrowserStack Automate lets you test on multiple twist and browser combination at once, speeding up test execution and cater quick feedback.
  • Real Devices and Browsers:Testing on real device and browsers ensures accurate execution penetration, unlike emulators. You can test on the latest devices without buying them.
  • Dedicated Dashboard:Automate offers a dashboard to track and manage your tests, present test condition (Pass/Fail/Pending), device point, test duration, screenshots, and more.
  • Custom Reports with Artifacts:Generate detail, customized report including exam position, device/browser configurations, video recordings, and screenshots.
  • Easy Integration with CI/CD:Seamlessly integrate with CI/CD creature like Jenkins, TeamCity, and TravisCI for faster, reliable, and logical application delivery.

Talk to an Expert

Conclusion

Ideally, it is recommended as a best practice to separate the test event involving Captcha and run them singly. Additionally, if the test are not conduct on the live code that is deployed already, so the testers could disable the Captcha faculty when they do automated UI quiz.

Bear in mind that Selenium tests must be run on real devices for accurate results. Start running examination on 3500+ real browser and devices on BrowserStack ’ s. Run parallel tests on a to get fast resolution without compromising on accuracy. Testers can also behave on 30+ real browser version across Windows and macOS. Detect bugs before users do by testing package in with BrowserStack Automate.

Useful Resources for Automation Testing in Selenium

Methods, Classes, and Commands

Configuration

XPath

Locators and Selectors

Waits in Selenium

Frameworks in Selenium

Miscellaneous

Best Practices, Tips and Tricks

Design Patterns in Selenium: Page Object Model and Page Factory

Action Class

TestNG and Selenium

JUnit and Selenium

Use Cases

Types of Testing with Selenium

Tags
42,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free