Selenium unable to locate button in email template

Viewed 38

I am trying to use Selenium to locate a button in an email template and click it, but no matter what I use (xPath, css_selector) it seems that my code cannot locate the button and keep getting this error.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:

The email is in Mailinator, I am able to access Mailinator and the email body, but when the click action is about to perform, my code fails throwing the above error code.

Did anyone ever experienced this issue and can help me to understand what I am doing wrong? Please if you need more info just let me know. Thank you very much for your time and help

1 Answers

Looks like it's an iframe, if it is, you need to switch first before interaction :

Code :

wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "iframe xpath here")))

and then you can interact :

wait.until(EC.element_to_be_clickable((By.XPATH, "email field xpath here"))).send_keys('pass some email address')

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

once done, switch to default content like this :

driver.switch_to.default_content()
Related