Ashwin Balaji Kuppuraj Ashwin Balaji Kuppuraj - 1 month ago 17
Javascript Question

Why Gmail Password field couldnt be sent keys with "sendkeys" in Selenium Webdriver (Java)?

Am getting error as "Element is not visible" while running below code.

When I checked through google and on some investigation, found that Password is coming with "Password-hidden" attribute. How do I get rid of this.

driver.get("http://www.gmail.com");
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try{
driver.findElement(By.xpath("//input[@id='Email']")).sendKeys("ashwinxxxxx@gmail.com");
driver.findElement(By.xpath("//input[@id='next']")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[2]/div/div/input[2]")).sendKeys("abcd2123");
driver.findElement(By.xpath("//input[@id='signIn']")).click();
}
catch (Throwable e)
{
System.out.println(e.getMessage()); }
}

Answer

Try to find element using id as below:

WebElement element1 = driver.findElement(By.id("Passwd"));
element1.sendKeys("Password");

If it fails, post the exception or error being received.

WebDriverWait wait = new WebDriverWait(driver, 15);
WebElement element1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
element1.sendKeys("Password");
Comments