4

Currently, I automate some processes using selenium and need to solve Google ReCaptcha. The technology used to solve the ReCaptcha is the browser, Plugin Buster. I enter the Google ReCaptcha using the following

driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
check_box = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "recaptcha-anchor")))
check_box.click()

Now I switch back to the default Frame using:

driver.switch_to.default_content()

So I need to click the Buster icon, but how to do that?

Icon to click:

Icon to click

Tomain
  • 75
  • 1
  • 1
  • 6

1 Answers1

2

The Buster icon is within another sibling <iframe>. So you have to:

  • Switch back to the default_content().

  • 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 the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    driver.switch_to.default_content()
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"//iframe[@title='recaptcha challenge']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='solver-button']"))).click()
    
  • Browser Snapshot:

recaptcha_iframe


Reference

You can find a couple of relevant discussions in:


Outro

Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 3
    solver-button is now inside a closed shadow DOM. Last line of your code doesn't work anymore. – abbr Mar 02 '21 at 18:42
  • @abbr any ideas for closed shadow DOM? – Nam Vu May 11 '21 at 06:52
  • 1
    @NamVu, I Submitted an issue to Buster github about closed shadow DOM. Author of buster replied Buster is not designed for automated testing script and deleted the issue ticket. – abbr May 11 '21 at 17:23