How can I automate "Enter CAPTCHA" using Selenium WebDriver?
You don't, that is the whole idea behind a good CAPTCHA.
CAPTCHA stands for:
Completely Automated Public Turing test to tell Computers and Humans Apart
So, by definition, resolving a CAPTCHA cannot be automated: Otherwise, it could not tell computers and humans apart and hence fails to be a CAPTCHA.
How to handle a CAPTCHA in a test environment:
- If you need to test an application which uses CAPTCHA, then you need to get the development team to build in a workaround/backdoor which is only active in the test environment.
- Use a service like http://www.deathbycaptcha.com which has an API to return the text of the CAPTCHA for you. The average response is 15 seconds with a result rate of 90% or so they say. Sounds like something to try.
We cannot automate CAPTCHA, as it is not meant to be automatized.
How to deal with CAPTCHA?
Either ask dev team for a workaround, like configure CAPTCHA in test environment in such a way it will always accept 1 specific value.
Ask developer to disable the CAPTCHA module in testing environment.
If your are using custom CAPTCHA module, you can ask developer to generate an API of CAPTCHA generation for testing environment.
You can ask dev team to add CAPTCHA code as
titlein markup, then you can access this title and bypass the CAPTCHA, but only in the testing environment.
Most of the time we go with option 1 or 2.
NOTE: When you do work around for CAPTCHA in test environment, You should always have this point in your checklist to make sure workarounds for CAPTCHA testing are removed before it goes on production.
As other posters explained, whole point of CAPTCHA is that recognition cannot be automated with our current pattern recognition programs. Even as AI algorithms solving pattern recognition will improve, new CAPTCHA will be developed.
So what you need is automated humans - a web service which outsources solving CAPTCHA, for like $1 per 1000 CAPTCHA solved. You post image to the service API, real humans in some country with cheap labor solve them within seconds, and send you answer back.
Long live human ingenuity!
For simple CAPTCHAs like the one below you can first extract the image with Selenium and then send it to the free OCR.space OCR API for processing. This will return the text inside the (Captcha) image.
If you're trying to automate a CAPTCHA like Google reCAPTCHA, well, you just can't. Simple reason being the CAPTCHA code is updated and added to very frequently.
You may be able to automate some other CAPTCHA that use a limited database. Such CAPTCHA will have a limited number of code. You can somehow make a list of all the available codes and their IDs. I'm sure they'll have some sort of unique identification. Once you have that data, while automating it you can fetch the ID of the captcha being called, search in your list and filling in the value associated with that CAPTCHA in the text field. I remember this being told to me by Santhosh Tuppad a couple of years ago.
To automate modules that make use of CAPTCHA field you can,
Ask your development team to remove the CAPTCHA field on the test environment.
Ask them to make a sandbox like CAPTCHA, that will accept a single input text every time.
Ask them to make a working model sandbox of the CAPTCHA, where each time the CAPTCHA text will be generated dynamically, but the same text will also be inserted in the text field or there is some way for you to know the text field generated, so that you can insert that in the text field.
There are tools and services to accomplish this, 75% of the time. The question reminded me of a piece of software called JDownloader, a download manager with CAPTCHA bypass abilities. According to their thread on the topic, they support many services in addition to their own automated OCR tool.
Some services they use:
- 9kw.eu - credit exchange service
- Captcha Brotherhood - credit exchange and OCR
- ImageTypers - pay-to-solve service
- Death By Captcha - pay-to-solve, OCR, and API manipulation
Their tool, JAntiCaptcha, in SearchCode.
Depending on your language, integrating one service or another may be more challenging, so be sure to do your research.
How can I automate, 'Enter CAPTCHA' using Selenium Web Driver ?
Presumably you don't really want to test the CAPTCHA feature, you just want your automation to go past that portion of your application, so that you can test the remainder using automation.
If that's the case, you need to get your developers to give you a "back-door" - basically a test-only version of the page that will let you bypass the CAPTCHA feature and continue on.
Talk to your developers. Explain your predicament. Ask them to propose a solution.
In the past, I've had developers give me a "replacement" page for testing. It omitted the CAPTCHA but contained everything else.
You can bypass No CAPTCHA reCAPTCHA - details are on the Google Dev FAQ:
I am presuming that you want to create automation for validating CAPTCHA, & you are familiar with automation with Databases.
Captcha is same concept in terms of generating automatically like OTP. It has been generating in back end and some scripting mechanism used to wrap those codes in to configuration which can be identify by human , only .
So In order to automate testing of it you can divide into two parts , one is automation using just getting back end CAPTCHA Data and store in variable and validate by inputting into captcha block using webDrviver & pass that captcha challenge. while other practice you need to verifying that captcha to be solve its purpose for human readable form only , you need to do manual testing for verification.