3

I've written a script in python using selenium to tick a checkbox and hit the submit button. When I follow the steps manually, I can do it without solving any captcha. In fact, I do not face any captcha challenge. However, the site throws captchas as soon as I initiate a click on that checkbox using the script below.

website address

This is what I've tried so far:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get('https://www.truepeoplesearch.com/results?name=John%20Smithers')

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_css_selector("iframe")))
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()

How can I click on a checkbox in a webpage using selenium without triggering captchas?

4
  • can you share the screenshot,where you are selecting the checkmark. I don't see the captcha populating when tried to navigate to this page. Commented Mar 20, 2020 at 18:02
  • When I execute the script, it triggers captchas. Here is the screenshot @supputuri. However, when i visit the site manually, I do see the checkbox but I don't encounter captchas when I tick on that checkbox. Thanks. Commented Mar 20, 2020 at 18:10
  • Well, in that case selecting checkbox it self does not resolve your issue. You have to find a way to resolve the captcha. Btw, have you tried with your default chrome profile to see if it's still showing the recaptcha ? Commented Mar 20, 2020 at 18:14
  • If this is what you meant, it still triggers captchas @supputuri. Thanks. Commented Mar 20, 2020 at 18:31

4 Answers 4

3

You can use the PyMouse package (python package here) to move to the (x,y) position of the object on the webpage and simulate a mouse click.

from pymouse import PyMouse

mouse = PyMouse()
def click(self, x,y):
    """Mouse event click for webdriver"""
    global mouse
    mouse.click(x,y,1)
Sign up to request clarification or add additional context in comments.

Comments

2

CAPTCHA is used to stop website automation & that's why it can not be automated using selenium. Adn for same reason, your not able to select CAPTCHA tick box. Please refer these link for more info: https://sqa.stackexchange.com/questions/17022/how-to-fill-captcha-using-test-automation

Comments

2
+75

Here is the sample code to select the check box that will trigger the recaptcha images.

url = "https://www.google.com/recaptcha/api2/demo"
driver.get(url)

driver.switch_to.frame(driver.find_element_by_xpath("//iframe[starts-with(@name,'a-')]"))
# update the class name based on the UAT implementation (if it's different)
driver.find_element_by_class_name("recaptcha-checkbox-border").click()

But still you have to complete either image selection/use voice-to-text api to resolve the captcha. The possible options are using 3rd party APIs or check you have the APIs available in truepeoplesearch where you can get the required information as response.

Edit 1: Using the API and html parser.


url = "https://www.truepeoplesearch.com/results?name=John%20Smithers"

payload = {}
headers= {}

response = requests.request("GET", url, headers=headers, data = payload)

html_content = response.text.encode('utf8')
# now you can load this content into the lxml.html parser and get the information

html_content = response.text.encode('utf8')
root=lxml.html.document_fromstring(html_content)
content=root.xpath("//div[@class='h4']") # here I am get the names
for name in content:
    print(name.text_content() + '\n')

2 Comments

Check if you are able to get the information using API as shown in the updated answer.
Added the complete logic to print the names, you can parse any details using the same approach.
2

If you are working on the team that develops this site, you can agree with the developers about an efficient way to work around the captcha.
For example, they could made a case in the code, captcha to not be shown if there is a cookie with hard to guess name, known only to you and them. Potentially someone can guess that cookie, but if you have no other choice, this is an option.

You can also use a separate key for testing environments as explained here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.