0

Why I am getting a no such element exception error when the code is right, when i click on gmail the link opens in new tab but doesn't send the email as key?

@Test
public static void gDem() throws InterruptedException{

    System.setProperty("webdriver.chrome.driver", "D:\\Edu Stuff\\Selenium\\Selenium Softs\\Other Softs\\Drivers\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().deleteAllCookies();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    driver.get("http://www.google.ca");
    driver.findElement(By.linkText("Gmail")).click();

    driver.findElement(By.linkText("Sign in")).click();
    Thread.sleep(3000);

    driver.findElement(By.xpath("//input[@id='identifierId']")).sendKeys("abhi.abhib5");

    Thread.sleep(2000);
    driver.close();

}
jhamon
  • 3,603
  • 4
  • 26
  • 37

1 Answers1

0

If its open a new tab you need to switch to that tab window before performing actions of that tab window.try below

  // this is to keep your parent window
 String parentWindow = driver.getWindowHandle();
 driver.findElement(By.linkText("Sign in")).click();
 Thread.sleep(3000);

 // since new tab is opened get new winodw handles and switch
 ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());        
 driver.switchTo().window(tabs.get(1));

driver.findElement(By.xpath("//input[@id='identifierId']")).sendKeys("abhi.abhib5");

Thread.sleep(2000);

// if you have further actions in parent window you need to switch back to the parent window
driver.close();