In my web appilcation, i need to click on the cancel button of the print preview window of chrome that comes up. I found some code in web to switch between the windows, but for some reason, it doesnt seem to be working. please help.
driver.findElement(By.xpath("//*[@id='PrintBill']")).click();
driver.findElement(By.xpath("//*[@id='savebill']")).click();
// This is in the parent window.
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
driver.findElement(By.xpath("//*[@id='print-header']/div/button[2]")).click();
//this is in the child window(print preview window)
This is where i found the code from... http://seleniumwebdriverfaq.blogspot.in/2012/02/how-can-i-switch-webdriver-control-to_4426.html