Krishnan has an important question to consider. If you are trying to automate Gmail so you have a service to use for testing there are a number of reasons this is a bad idea. The most important reasons are:
- Automating Gmail is difficult and you aren't on the Gmail team, therefore you won't know they change things before your tests start failing
- When doing test automation you want email to be immediate but using Gmail could result in delays because it is a real email service
- If you are testing an application before it is released to the public and using Gmail to test it then you are sending private information from the application to a public service, i.e. Gmail. You could be breaching security or a NDA
You can use something like
mountebank to mock out an SMTP server.
If you are just practicing and want to use Gmail as something to automate, first note that Gmail is so far from a static website that automating it without inside information can be very difficult. That said, look at two or more Gmail accounts and see if there are similarities between the DOM on the two accounts. Log out and log in to the same account then see if there are similarities between the DOM. You will need to be able to spot the patterns which are unique and consistent. For example, I believe the best locator for the Compose button in Gmail is:
WebElement composeButton = driver.findElement(By.cssSelector("[gh='cm']"));
composeButton.click();
I would assume that people on the Gmail team understand that there will always be one element which has the above attribute for the Compose button. If it changes however you tests will fail. In some cases the Gmail team but have a database (spreadsheet, property file, whatever) of locators and they change the locators every so often to throw people like us. For the people on the team, if the application and the tests are using the same database of locators then when they change the database, all the tests will keep working but since we don't have access to the database, our tests will fail. Just one possibility for why automating an application you are not working on can be fraught with problems.