Webdriver to open a mail in Gmail Webdriver to open a mail in Gmail selenium selenium

Webdriver to open a mail in Gmail


I would suggest NOT to use UI to verify Gmail. Gmail's UI is extremely complicated and it's a trap. To me, automating with selenium is not a solution at all.

Consider using JavaMail API and HTTPURLConnection. This is what I do in a similar testing scenario.

While running the webdriver test, after doing certain action if you expect an email then using JavaMail API poll (for a certain timeout if its not immediate) for the email in the background with certain 'subject' or 'sender' etc. Once the email is found then grab the link from the email content and then simulate a click using HTTPURLConnection


If you can search the specific email you can use the following code to locate the email you are looking for:

//div [@class='y6']/span[contains(.,'<your original search text>')]

mind that google will cut off the subject which results in something like 'subject...' if the subject is too long. We use a unique number to identify messages in our automated test environment.


I don't think I got your question correctly but I suppose you are having trouble finding the locator to open the mail after you've entered text in search box of gmail.

//div[5]/div/div/table/tbody/tr[n]" //n is the row no. of mailbox, for first result use 1 and like

use this as identifier for element before cliking on it.

Hope this helps.