'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 1:[1]

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

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

might.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BuddyBob