title: Target window closed in selenium
body: <p>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</p>
  
  <pre><code>org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
  </code></pre>
  
  <p>Screenshot</p>
  
  <p>Below are the details
  <a href="http://i.stack.imgur.com/gCvWO.jpg" rel="noreferrer">Screenshot</a></p>
  
  <p>Below is the code</p>
  
  <pre><code>@Test
  public void testing()
  {
      driver.manage().window().maximize();
      driver.get("http://www.seleniumframework.com/Practiceform/");
      driver.findElement(By.id("button1")).click();
      Set&lt;String&gt; 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();
  </code></pre>