Search code examples
pythonseleniumemail-confirmation

Python Selenium - clicking on the account confirmation link in the email


I want to write a test in selenium python. This is what i would like to acheive.

Steps:

  1. Create an account on XYZ
  2. then, go to gmail or outlook
  3. Go to inbox mail
  4. find confirmation email
  5. click on the confirmation email
  6. Logout

I would like to know if it is a good idea to login to gmail or outlook and click on each elements using browser. Is there any python library that i can use to achieve this without using a browser?

thanks in advance!


Solution

  • I belive the easiest way of getting the confirmation mail is using the module poplib. Just receive the mails and look for the URL with a regular expression. The open is with urllib.

    Example from the docs:

    import poplib
    
    M = poplib.POP3("pop.gmail.com")
    M.user("user")
    M.pass_("pass")
    numMessages = len(M.list()[1])
    for i in range(numMessages):
        for j in M.retr(i+1)[1]:
            print j