Home > Software engineering >  Why can't selenium locate the 'Send Me a Push' button?
Why can't selenium locate the 'Send Me a Push' button?

Time:08-21

The page I'm trying to access requires 2FA. If I click the 'Send Me a Push' button, it will send a request to my phone to approve. However, when I try to find the button via the following methods, I get a NoSuchElementException (or timeout if I ask selenium to wait for the element to be clickable). Methods used:

driver.find_element()
- By.XPATH, '/html/body/div[3]/div[2]/div[1]/form/div[2]/div[2]/p[2]/input'
- By.CSS_SELECTOR, '#auth_methods button'
- By.CLASS_NAME, 'positive.auth-button'

CodePudding user response:

That page has an <iframe>, which is a common cause of errors like this. Elements in the iframe are not actually part of the page source.

If the desired element is inside the iframe, you have to specifically tell selenium to switch to the frame with driver.switch_to.frame(iframe_element)

  • Related