Gmail login fail using Selenium webdriver. Showing element not found for password.

We can encounter Gmail login failure while using Selenium webdriver due to the error - element not found for password. This can be fixed by the methods listed below −

  • Adding implicit wait - Implicit wait is applied to instruct the webdriver for polling the DOM(Document Object Model) for a specific amount of time while attempting to identify an element that is currently unavailable.

    The default value of the implicit wait time is 0. Once a wait time is set, it remains applicable throughout the entire life of the webdriver object. If an implicit wait is not set and an element is still not present in DOM, an exception is thrown.


driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

              Here, a wait time of five seconds is applied to the webdriver object.

  • Adding explicit wait - Explicit wait is applied to instruct the webdriver to wait for a specific condition before moving to the other steps in the automation script.

    The explicit wait is implemented using the WebDriverWait class along with expected_conditions. The expected_conditions class has a group of prebuilt conditions to be used along with the WebDriverWait class.

    Here, we can add the expected condition visibilityOfElementLocated for the element not found error for the password field in Gmail.


Code Implementation

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.concurrent.TimeUnit;
public class FirstAssign{
   public static void main(String[] args){
      System.setProperty("", "chromedriver");
      WebDriver driver = new ChromeDriver();
         //implicit wait of 15 seconds
         driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
         //application launch
         WebElement e = driver.findElement
         (By.xpath("//input[@type = 'email']"));
         WebElement n = driver.findElement
         (By.xpath("//button[@type = 'button']"));;

         //explicit wait
         WebDriverWait wait = new WebDriverWait(driver, 10);
         WebElement m = wait.until(
         (By.xpath("//input[@type = 'email']")));
         ("//input[@type = 'email']")).sendKeys("1234");;
      catch (Exception e)
         // TODO Auto-generated catch block