2

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Your object is in an 'iframe' - you need to switch to that frame in order to identify it with selenium... However - If this site has a captcha it doesn't want you automating it, this will be the tip of the iceberg in issues you'll face. Captchas are designed to stop bots & automation - if they didn't work, people wouldn't use them – RichEdwards Feb 16 '21 at 16:05

2 Answers2

1

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
<iframe src="https://www.google.com/recaptcha/api2/anchor?ar=1&amp;k=6LepxvIZAAAAAPGd49tlErQ-2da9Bh-3yN_gCjul&amp;co=aHR0cHM6Ly93aGl0ZXBhZ2VzLmNvLm56OjQ0Mw..&amp;hl=en&amp;v=2Mfykwl2mlvyQZQ3PEgoH710&amp;size=normal&amp;cb=r4uh76mv0o72" width="304" height="78" role="presentation" name="a-taqeeo56s3nk" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox"></iframe>

Switch over to the iframe after you get the sitekey.

wait = WebDriverWait(driver, 10)
driver.get("https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F")
print(driver.find_element_by_class_name("g-recaptcha").get_attribute("data-sitekey"))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "#contentMainSearchResults > form > div > div > div > iframe")))

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32