As per my understanding problem with gmail is: It have 2 pages for login.
- User Name
- Password
So steps should be:
- Enter user name
- click on Next
- Enter password.
- Click on signin.
Sharing the sample code. Just remember google have change their page. So giving both code which work on new page as well as on old page.
driver.get("http://www.gmail.com");
// **** checking if url is of new then use if code otherwise else code.
if(driver.getCurrentUrl().contains("https://accounts.google.com/signin/v2/identifier?")){
driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxx");
driver.findElement(By.id("identifierNext")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password")));
driver.findElement(By.name("password")).sendKeys("xxxxxxxx");
driver.findElement(By.id("passwordNext")).click();
}
else{
driver.findElement(By.name("Email")).sendKeys("xxxxxxxxx");
driver.findElement(By.id("next")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Passwd")));
driver.findElement(By.name("Passwd")).sendKeys("xxxxxx");
driver.findElement(By.name("signIn")).click();
}
I hope it will help you. Please ignore the multiple creation of wait object. Just provide the snippet.