title: How to close child browser window in Selenium WebDriver using Java
body: <p>After I switch to a new window and complete the task, I want to close that new window and switch to the old window,</p>
  
  <p>so here i written like code:</p>
  
  <pre><code>// Perform the click operation that opens new window
  
  String winHandleBefore = driver.getWindowHandle();
  
      // Switch to new window opened
  
      for (String winHandle : driver.getWindowHandles()) {
          driver.switchTo().window(winHandle);
      }
  
      // Perform the actions on new window
  
  
      driver.findElement(By.id("edit-name")).clear();
      WebElement userName = driver.findElement(By.id("edit-name"));
      userName.clear();
                try
      {
          driver.quit();
      }
  
      catch(Exception e)
      {
          e.printStackTrace();
          System.out.println("not close");
                  }
  
  driver.switchTo().window(winHandleBefore);// Again I want to start code this old window
  </code></pre>
  
  <p>Above I written code <code>driver.quit()</code> or <code>driver.close()</code>. But I am getting error. Can anybody help me...?</p>
  
  <blockquote>
    <p>org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.</p>
  </blockquote>