How to work with a selenium script where the if found captcha is in the mid of the script. Is it possible to pass the captcha and continue the automation script?
The Selenium website is full of documentation. They have a section called Test Practices which contains encouraged and discouraged practices. One of the discouraging practices talk about CAPTCHAS
Discouraged practices are things to avoid when using test automation. It's a myth that everything can be automated or should be automated. In fact, not everything can be or should be automated. There are a number of factors that should be considered when writing test automation.
When it comes to CAPTCHAS, Selenium documentation says:
CAPTCHA, short for Completely Automated Public Turing test to tell Computers and Humans Apart, is explicitly designed to prevent automation, so do not try! There are two primary strategies to get around CAPTCHA checks:
- Disable CAPTCHAs in your test environment
- Add a hook to allow tests to bypass the CAPTCHA
So, what does this mean? It means you can't use a computer to bypass a CAPTCHA.
In your test environment, it's a good practice to disable CAPTCHAs. If your application uses them, you really only need to test the integration of the CAPTCHA library, not the implementation of the CAPTCHA library. Once the integration is tested, you can safely disable it in your test and stage environments. CAPTCHAs are only effective in a production environment. This can be done via a feature flag.
My view points to handle captcha :
- This is one of the limitation of automation to automate or handle captcha
- There is not straight way to handle captcha or discard, by pass like popups, alerts
- As it is mandatory step, even if you just avoid captcha somehow with hackish way, still you can not progress to test actual flow and scenario
On top of this for testing purpose there are few possible work around [Not recommended] as follows :
- By disabling Captchas in test environments
- By clicking the reCAPTCHA checkbox in Selenium
- By adding a delay in your selenium script and manually solving Captcha while running
Note - If you are interested for more details for those work around. Please refer this.