title: Closing new window in Selenium
body: <p>I have written the following code to open a google map window get it's url then close it and perform the actions on my previous window:</p>
  
  <pre><code>        try 
            {
  
             String winHandleBefore = driver.getWindowHandle();
              element("icon_google_map").click();
              for(String winHandle : driver.getWindowHandles())
               {
                  driver.switchTo().window(winHandle);
               }
             Thread.sleep(9000);
              String currentURL = driver.getCurrentUrl();
              logMessage(currentURL);
              String expectedURL="xyz";
              Assert.assertEquals(currentURL, expectedURL);
              logMessage(currentURL);
              driver.close();
              driver.switchTo().window(winHandleBefore);
              return true;
      }
      catch(Exception e)
      {
          return false;
      }
  </code></pre>
  
  <p>The code above opens the map window but does not close it,instead it shows the following error when i perform the action on previous window.</p>
  
  <p>Error:
  org.openqa.selenium.NoSuchWindowException: no such window: target window already closed</p>