0

I was just trying to automate the Gmail login process using Selenium WebDriver...After the email id is entered a new page opens to enter the password. How do I enter the password?

WebElement element= driver.findElement(By.xpath("//*[@id='ident']"));
element.sendKeys("THE EMAIL ID");
element.sendKeys(Keys.ENTER);
WebElement ele= driver.findElement(By.xpath("//*[@id='passd']"));
ele.sendKeys("THE PASSWORD");
ele.sendKeys(Keys.ENTER);
  • Possible duplicate of [Selenium test scripts to login into google account through new ajax login form](https://stackoverflow.com/questions/45953043/selenium-test-scripts-to-login-into-google-account-through-new-ajax-login-form) – undetected Selenium Nov 30 '17 at 13:27

1 Answers1

1

You have to switch the driver to current handler.

Please use below code to enter password.

   WebElement element= driver.findElement(By.xpath("//*
   [@id='ident']"));
   element.sendKeys("THE EMAIL ID");
   element.sendKeys(Keys.ENTER);

   String mainWindowHandler = driver.getWindowHandle();

   for(String winHandle : driver.getWindowHandles()) {
       if (!mainWindowHandler.equals(winHandle)) {
           driver.switchTo().window(winHandle);
       }
   }

   WebElement ele = driver.findElement(By.xpath("//*[@id='passd']"));
   ele.sendKeys("THE PASSWORD");
   ele.sendKeys(Keys.ENTER);
Mahmud Riad
  • 1,169
  • 1
  • 8
  • 19