Unable to locate element. How to fix?

Viewed 41

Well, i coded this, but i don't know why it doesn't work :(. Please help me out!!

    while True:
        try:
            driver.switch_to.frame(0)
            driver.switch_to.frame(0)
            driver.find_element(By.CSS_SELECTOR, "#recaptcha-anchor > div.recaptcha-checkbox-border")            
            driver.refresh()

        except NoSuchElementException:
            break
        pass

    driver.find_element(By.ID, "email").send_keys(email)

It raised the error Exception has occurred: NoSuchElementException Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="email"]"} (Session info: chrome=105.0.5195.102)

1 Answers

It appears that i'd switched to a frame but didn't switch back to default content. so by using driver.switch_to.default_content() after the loop, it worked

Related