I have a button in IE, when clicked on the button it opens a new window with a pdf file in it.
while using IE webdriver, pdf is not loaded and the new window is not getting detected.
String parentHandle = DriverFactory.getDriver().getWindowHandle(); // get the current window handle
Set<String> winHandles = DriverFactory.getDriver().getWindowHandles();
int numberOfWindows = winHandles.size();
DriverFactory.getDriver().findElement(By.xpath("//input[@value='Preview Letter']")).click();
System.out.println("2 : number of windows are" + winHandles.size());
System.out.println("2 : the title of page is" + DriverFactory.getDriver().getTitle());
System.out.println("2 : the title of page is" + DriverFactory.getDriver().getCurrentUrl());
for (String winHandle : DriverFactory.getDriver().getWindowHandles()) {
DriverFactory.getDriver().switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
System.out.println("3 : number of windows are" + winHandles.size());
System.out.println("3 : the title of page is" + DriverFactory.getDriver().getTitle());
System.out.println("3 : the title of page is" + DriverFactory.getDriver().getCurrentUrl());
//code to do something on new window
DriverFactory.getDriver().close(); // close newly opened window when done with it
DriverFactory.getDriver().switchTo().window(parentHandle); // switch back to the original window