I'm having testcase for handle the popup but control is not going to popup window. It is displaying the getTitle of main window instead of popup window. can you go through below code.
@Test
public void testText1() throws Exception {
driver.get("http://www.hdfcbank.com");
Thread.sleep(8000);
driver.findElement(By.xpath(".//*[@id='loginsubmit']")).click();
String popupHandle = driver.getWindowHandle();
WebDriver popup;
popup = driver.switchTo().window(popupHandle);
System.out.println(popup.getTitle());
if (popup.getTitle().equals("netbanking")) {
System.out.println("I am going to access the elements of popup");
driver.findElement(By.xpath(".//*[@id='wrapper']/div[6]/a/img")).click();
} else {
System.out.println("Worth Trying try harder to get success");
//
}
}
Output: {d0f39d30-49e7-4203-b9ef-10380fbfcb5e} HDFC Bank: Personal Banking Services I am going to access the elements of popup Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='wrapper']/div[6]/a/img"} Command duration or timeout: 30.15 seconds