pythonseleniumcaptchahcaptcha

Selenium can't found valid item from iframe


I have code:

self.driver.execute_script(f'document.getElementsByName("h-captcha-response")[0].setAttribute("h-captcha-response", "{token}")')
self.driver.execute_script(f'document.getElementsByName("g-recaptcha-response")[0].setAttribute("g-recaptcha-response", "{token}")')
self.driver.find_element_by_id('checkbox').click()
time.sleep(5)

and that code don't click at the item with id checkbox (check screenshot)

i think the iframe upper makes big problems (check screenshot)

if this is right version of solving problem, how to refocus Selenium onto that iframe?


Solution

  • I dont think that driver.switchTo().frame(iframe); would work but

    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name,'a-')]")));
    

    might.