Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message: no such element: Unable to locate element: {"method":"css selector","selector":".recaptcha-checkbox-border"}

I am trying to bypass the captcha verification using Selenium but I keep getting this error

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".recaptcha-checkbox-border"}

I have already tried using sleep(20) and it doesn't work. Here is the link that I am trying to bypass captcha on: https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F

Please let me know if I am making a mistake in the the selector class or anything.

like image 616
Sanju Gautam Avatar asked Nov 20 '25 07:11

Sanju Gautam


1 Answers

The reCAPTCHA is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get("https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()
      
    • Using XPATH:

      driver.get("https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@src, 'https://www.google.com/recaptcha/api2/anchor')]")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='recaptcha-checkbox-border']"))).click()
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

whitepages


Reference

You can find a couple of relevant discussions in:

  • Ways to deal with #document under iframe
  • Switch to an iframe through Selenium and python
  • Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome
  • How to interact with the reCAPTCHA audio element using Selenium and Python
  • Find the reCAPTCHA element and click on it — Python + Selenium
like image 103
undetected Selenium Avatar answered Nov 22 '25 04:11

undetected Selenium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!