DEV Community

Cover image for Testing Emails with Selenium

Testing Emails with Selenium

razgandeanu profile image Klaus ・2 min read

Selenium is widely used, but it's a little known fact that you can use it to test anything built with HTML and CSS, including Chrome Extensions and Emails.

We'll create a simple test for the Register page from Swit and then we'll test the email that we receive.

I'll also be making some comparisons between Selenium and Endtest:

Selenium can only interact with HTML elements if they're in a browser.

This means that we'll have to open our email in a browser.

Luckily, anyone can use the Endtest Mailbox for free.

The way it works is similar to a disposable email service.
Simply send your email(s) to a email address.

The username can be anything you choose.
For instance, you can choose something like

You can access the Inbox for that email address on that page.

Just add the email parameter in the URL, like this:

Please note that the emails will be deleted after 2 hours.

But for now, let's get back the Register page from Swit:


firstName = driver.find_element_by_id("firstName")
lastName = driver.find_element_by_id("lastName")
email = driver.find_element_by_id("id")
password = driver.find_element_by_id("password")
confirmPassword = driver.find_element_by_id("confirmPassword")
submitButton = driver.find_element_by_class_name("button--important")


And here is the result:

Now, if we want to check that email, we have to go to:

And we'll be able to open our email:

We just have to write that part with Selenium:

email = driver.find_element_by_class_name("email_item")

Since you're planning to run that test multiple times, you should generate a random email and store it in a variable and then append it to the Endtest Mailbox URL.

If you're looking for a better Selenium alternative, switch to Endtest.


Editor guide