-1

I'm trying to make a bot that logs inside my account. After inserting psw and username I make my bot clicking on "I'm not a robot" recaptcha checkbox.

After flagging the Recaptcha checkbox it could randomly appear a second Recaptcha, this time one with images. Fine, I could solve it by using the audio to text method. The issue is that this Recaptcha appears randomly.

I used an explicit wait but it gets bypassed and doesn't give me any errors.

Here's my code

#solve first recaptcha (I'm not a robot)
driver.switch_to_frame(element)                   #element = captcha frame already found
recaptcha = driver.find_element_by_xpath('//*[@id="recaptcha-anchor"]/div[1]')
driver.execute_script("arguments[0].click();",recaptcha)
_delay()

driver.switch_to_default_content()

#if an image captcha frame appears click on the audio button 

try:
    recaptcha_frame = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, 
'/html/body/div/div/div[3]/div[2]/div[1]'))).find_element_by_tag_name('iframe') #locating the recaptcha image frame
        
    driver.switch_to_frame(recaptcha_frame)
    audio_button = driver.find_element_by_class_name('rc-button goog-inline-block rc-button-audio')
    driver.execute_script("arguments[0].click();",audio_button)
  
except:
    pass

If i would have used driver.quit() instead of pass it would have closed the session. My aim is to click on the audio_button. Any wonder on why this explicit wait doesn't work?

vitaliis
  • 4,082
  • 5
  • 18
  • 40
neto
  • 19
  • 6

1 Answers1

0

I think you do not need using explicit wait if you already using implicit. This may be the first problem. For the implicit wait the code should look similar to this:

try:
    recaptcha = driver.find_elements_by_xpath("Your recaptcha_frame stable xpath")
    recaptcha.click()
except NoSuchElementException:
    pass

Also, /html/body/div/div/div[3]/div[2]/div[1] is not reliable locator. Change it to the stable one. In your code if this locator is not found, nothing will happen. Use a better exception type to understand the reason. If you go with explicit wait, try changing presence_of_element_located to visibility_of_element_located

But still, locator is the main problem in your code.

Also, I have doubts you will be able to pass recaptcha.

vitaliis
  • 4,082
  • 5
  • 18
  • 40