In the attached screenshot,i want to click New Browser Window. I want to close the browser window and click on New Message window. I closed the browser window. But i am getting the exception
org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
Screenshot
Below are the details Screenshot
Below is the code
@Test
public void testing()
{
driver.manage().window().maximize();
driver.get("http://www.seleniumframework.com/Practiceform/");
driver.findElement(By.id("button1")).click();
Set<String> handle=driver.getWindowHandles();
for(String handles:handle){
try{
String text=driver.switchTo().window(handles).getPageSource();
if(text.contains("Agile Testing and ATDD Automation")){
System.out.println("Text found");
driver.close();
break;
}
}catch(Exception e){}
}
driver.switchTo().defaultContent();
driver.findElement(By.xpath("//button[contains(text(),'New Message Window')]")).click();
driver.quit();