How to fill CAPTCHA using Test automation?
How can I automate "Enter CAPTCHA" using Selenium WebDriver?
If you could automate CAPTCHA, it would mean that it's a very poor implementation of CAPTCHA.
What do you need to use it for? Do you have a site with a CAPTCHA component that you still want to be able to test with Selenium, possibly by selectively disabling the CAPTCHA when testing?
In my opinion, you need a very powerful image processing algorithm and SikuliX. Selenium doesn't suit this.
On a similar note: If you _can_ automate CAPTCHA input (e.g. by simple OCR means), this is a serious quality issue and might be worth testing in future releases.
You can bypass No CAPTCHA reCAPTCHA - details are on the Google Dev FAQ: https://developers.google.com/recaptcha/docs/faq#what-happens-to-recaptcha-v1
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.
Unlike other answers there you show a good point: "a good captcha": many captcha implementations are easy to break (old page, but has many examples). Of course breaking the captcha isn't an recommended at all, but if someone got here because wants to use some captcha to prevent automation and want to know how someone can automate it then is important to know when a captcha is good or not.
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: