Nayden Van
Nayden Van

Reputation: 1569

Selenium loop through emails in Mailinator

Hello Selenium (python) experts. I have 2 emails in Mailinator where I am sending some email templates. I am calling those emails as follow to make it easy to explain my problem:

I am sending the exact same content to both email, and I am trying to target the email with selenium and open it.

Right now with selenium I am using the XPATH to target the email, but I realised that this XPATH is a dynamic link, which mean for each email I send, Mailinator generate a random number that attach to the email XPATH. for example:

email1 = //*[@id="row_email1-1626692999-529929"]/td[2]
email2 = //*[@id="row_email2-1628652999-526029"]/td[2]

I was wondering if there is an option to loop through the body of Mailinator and target all the email that contained the XPATH email1 or email2 and open them.

I am new to selenium, so please if something is not clear or need more infos, just let me know

Thank you so much guys

EDIT: this is the web driver configuration to run the browser in full screen mode but it start in small size

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(PATH, chrome_options=chrome_options)
wait = WebDriverWait(driver, 10)
driver.get('https://mailinator.com')

Upvotes: 1

Views: 659

Answers (1)

cruisepandey
cruisepandey

Reputation: 29372

You can use OR in xpath like below :

//*[@id='row_email1-1626692999-529929' or @id='row_email2-1628652999-526029']/td[2]

or a way better approach would be to use find_elements

for that, I am assuming the below xpath :

//*[contains(@id,'row_email')]/td[2]

would represent all the emails link.

Sample code :

for emails in driver.find_elements(By.XPATH, "//*[contains(@id,'row_email)']/td[2]")
    emails.click() or whatever you wanna do here with single mail link

Upvotes: 1

Related Questions