Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass Google reCAPTCHA for testing using Selenium

I am using Selenium to test my Spring based web application. Can you suggest a solution to bypass google reCAPTCHA while testing the application.

I am running automation test in this environment. So manually checking the "I'm not a robot" of reCAPTCHA is not possible.

For testing purpose I am using test key on my testing environment given on below location.

Google reCAPTCHA Testing Key

enter image description here

I am using Angular 5 as front-end of my application. I am using ng-recaptcha library for adding reCAPTCHA in ui.

like image 521
vivekkurien Avatar asked May 22 '18 11:05

vivekkurien


People also ask

How do I bypass captcha verification in Selenium?

In case you are using reCAPTCHA v2, you can put the Site Key and Secret Key also known as the test keys. These keys help in bypassing the CAPTCHA verification request and as a result, your automation case can run seamlessly. Once you enable the site keys you will see a warning message as shown below.

Can we automate captcha in Selenium?

The above mentioned ways are the only verified ways to handle CAPTCHA using Selenium Web Driver. Therefore, it is now very much clear that not everything can (or should) be automated, and CAPTCHA is one example where manual testing is still needed.


2 Answers

You can do this by finding the x and y coordinates of the checkbox in reCAPTCHA and click the element.

WebElement captcha = driver.findElement(By.xpath("html/body/div[1]/div[3]/div[2]/form/div[5]/div"));
        builder.moveToElement(captcha, 50, 30).click().build().perform();
like image 78
Joby Wilson Mathews Avatar answered Sep 22 '22 17:09

Joby Wilson Mathews


I don't know your exact code but you should be able to run your server with a System Property or some flag which indicate that the reCaptcha should be disable and to not add it to the form in the first place.

like image 37
Ido Ran Avatar answered Sep 22 '22 17:09

Ido Ran