I'm trying to click the captcha box in a website using the following code:
table = browser.find_element(By.CSS_SELECTOR, '#subs-content > table')
tts = random.randint(2,10)
for row in table.find_elements(By.TAG_NAME, 'tr')[::-1]:
martil_row = row.find_element(By.XPATH, './/*[contains(text(), "Martil")]')
if martil_row is not None:
print(martil_row.text)
time.sleep(tts)
WebDriverWait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
print('clicked!')
#browser.find_element(By.CSS_SELECTOR, "#recaptcha-anchor").click()
ch = browser.find_element(By.CSS_SELECTOR, '#recaptcha-anchor')
if ch.value_of_css_property('aria-checked') == "false":
print('false!')
driver.find_element(By.CSS_SELECTOR, '#recaptcha-audio-button').click()
time.sleep(tts)
browser.switch_to.default_content()
row.find_element(By.TAG_NAME, 'a').click()
break
print("Done!")
The problem is that it sometimes does click the box, but sometimes it doesn't and without raising any errors. It also does execute the code following it normally. (same goes for the child if statement)