3 cool tricks to Automate Captcha In Selenium

Automate Captcha in Selenium

CAPTCHA stands for ‘Completely Automated Public Turing Test to tell Computers and Humans Apart’. Captcha in Selenium is a problem that many testers struggle to find a solution for. This article will guide you to Automate Captcha In Selenium.

Automating UI testing for web applications becomes tricky when Captcha comes into the picture. In fact, the whole point of enabling Captcha itself does not fall in line with automation. As we all know, Captcha intends to prohibit bots from interfering with the application. And that’s the reason why Captcha can create a hindrance in a test scenario. So, how can we go ahead and Automate Captcha with Selenium? Is it even possible?  

It is inevitable to handle Captcha efficiently, to ensure that tests run without pullbacks. 

what is captcha?

Well, to be upfront automating Captcha is not the best practice and it is not advisable from a security perspective. But you can try these three efficient ways of handling Captcha in Selenium:

  1. Introduce a delay to the Webdriver & then manually solve Captcha while testing
  2. Disable the Captcha in the testing environment
  3. Add a hook to click the Captcha checkbox

Find out: Who Is An Automation Testing Engineer? & How To Become One?

Before we walk through each of these methods, let’s understand the following:

What is Captcha?

Automation is at its best in this digital era. But like every coin has two sides, these automation strategies can reverse the effect when taken over by Cybercriminals. As a prevention to these malicious attacks, Captcha or “Completely Automated Public Turing test to tell Computers and Humans Apart” is commonly used.

In short, Captcha is an important UI element that helps in restricting bots from accessing a web application. However, it is posing a major challenge for Automation Experts performing UI testing using Selenium. It is like, you purposely build something to create hindrance in the process and it in turn produces hindrance in the whole purpose! Funny!

To verify whether the user is a human or a bot, the user is put to certain tasks via Captcha. The tasks may include:

Enter some disfigured text:

what is captcha


Click on a set of similar images matching the image in the Captcha:

captcha handling in selenium

Moreover, some variants of Captcha also support visually impaired individuals. They generate audio instead of images.

Now, the trick is that the task is DYNAMIC. Yes! Only humans can take a call and answer the Captcha correctly. The correct interpretation of information is something that a bot fails to produce.

captcha automation in selenium

Handling Captcha-Enabled Web Applications in Selenium

Learning to automate Captcha in Selenium would beat the complete purpose of holding Captcha in the first place to confirm human interaction with the UI, it is very tricky to Automate Captcha in Selenium. 

  • Introduce a delay to the Web driver & then manually solve Captcha while testing
  • Let me tell you upfront that the technique of adding delay to the web driver is only a semi-automatic test; the reason being, that the user anyhow would have to solve and then enter the captcha manually.

    Delay in code

    In this technique, you have to introduce a delay of 10 to 20 secs. Thereby, freezing the Captcha screen. Usually, when we implement automation testing on a web page, there is a time-lapse. It happens because automation testing happens to be much faster than the reCaptcha. So, while the Captcha screen is still frozen, we hold enough time to enter the password and automate the whole process without the Captcha break! That’s wonderful. Isn’t it?

    Furthermore, using Python, you can easily insert a delay with time.sleep() command. You should definitely code this one!

    Wish to learn about Selenium Automation Testing: Get Started here!

  • Disable the Captcha in the testing environment
  • This is a simple tactic wherein we make sure that while testing a web application, the Captcha task is blocked-out! Yes! You can bypass Captcha altogether but only during the testing process is ongoing. By inserting the Site Key and the Secret Key, in Google’s open-source Captcha widget. Therefore, all verification requests will pass without any hindrances. And, you can automate your UI testing with no hurdles. 

    Login No Captcha reCAPTCHA – WordPress plugin |

    Most importantly, while doing so, the reCAPTCHA widget will show a warning alert. This will ensure that the CAPTCHA is bypassed, notably only for testing purposes. & BLING! Captcha would be back! So, this is a good option that will prevent Captcha while the Automation process takes place, bringing back Captcha, once the automation process gets over.

    Interested in Automation Testing: Learn everything here!

  • Add a hook to click the Captcha checkbox
  • This is another brilliant method of bypassing Captcha. We can add a hook to the code.

    Do you know, how Captcha recognizes a bot clicking the checkbox element? It’s actually simple! The bot takes less time to click as compared to humans.

    Captchas: An Annoying Illustration of Static Versus Dynamic Security —  Chris Louie, CISSP

    Now, this is the reason why automation testing Experts need to induce WebDriverWait. So, the element is clicked only when it becomes clickable. This, in turn, bypasses the Captcha. Problem solved!

    So, now do you know how to Automate Captcha in Selenium?

    You may automate your processes by inducing one of the above three methods and easily automate the captcha in selenium. Now that you know what is captcha and how to automate a captcha in Selenium, are you intrigued to take Automation Testing to the next level? Then find the link to our Automation Testing Program here

    Have any doubts? Please share it in the comment section below. We will get back to you shortly!

    Frequently Asked Questions(FAQs)

    Can we automate Captcha using Automation Anywhere?

    Yes! There is a feature named OCR(optical character recognition) in Automation Anywhere. OCR is used to extract text from the captcha image & enables the automation of Captcha.

    Is there any alternative to CAPTCHA?

    Yes! ‘Anti-spam Honeypot’ can be an alternative for both reCAPTCHA and CAPTCHA. How does this Anti-spam Honeypot work? It is basically a security mechanism built with the purpose to misguide bots with a trap. This mechanism provides something, (say an empty space created using CSS or JavaScript) that is going to attract the bot, as “honey”. This space appears hidden or invisible for human users.

    How do I write a CAPTCHA code?

    You can create a section for Captcha using HTML. And, with the use of a CSS file, we can add style and an image that can refresh with a click. JavaScript code will generate a new captcha by calling generate() method.

    What is the most commonly used CAPTCHA?

    Text-based CAPTCHA is one of the most commonly used CAPTCHA. They usually need human understanding through translation as they usually are displayed in a distorted fashion or an odd style.

    How do you solve a problem with a captcha?

    When a CAPTCHA fails to validate in your browser, just clear the browser cache(press Ctrl + Shift + Delete simultaneously) & redo the CAPTCHA.

    Contact Form

    By clicking 'Submit' you Agree to Guvi Terms & Conditions.

    Our Learners Work at

    Our Popular Course

    Share this post

    Author Bio

    A traveler, and explorer, Archana is an active writer at GUVI. You can usually find her with a book/kindle binge-reading (with an affinity to the mystery/humor).

    Our Live Classes

    Learn Javascript, HTML, CSS, Java, Data Structure, MongoDB & more
    Learn Python, Machine Learning, NLP, Tableau, PowerBI & more
    Learn Selenium, Python, Java, Jenkins, Jmeter, API Testing & more

    UX Processes, Design systems, Responsive UI, & more with placement assistance.

    Hey wait, Don’t miss New Updates from GUVI!

    Get Your Course Now

    Related Articles

    IIT Certified Automation Testing with Python

    This Certification Course will assist you in procuring a 360-degree view of automation technology.