title: Selenium Java open new window, close it, and control main window again
body: <p>I find my question to be different than everything that I've searched for because I need to open a new window in my code (not from clicking a link in a UI). So i already have a driver handling my only window, and then I do this:</p>
  
  <pre><code>//save the handle of the current (only) window open right now
  String MainWindowHandle = driver.getWindowHandle();
  //open a new firefox window
  driver = new FirefoxDriver();
  //in the new window, go to the intended page
  driver.navigate().to(foo);
  //do some stuff in the pop up window..
  //close the popup window now
  driver.close();
  //switch back to the main window. This is where the error is thrown
  driver.switchTo().window(MainWindowHandle);
  </code></pre>
  
  <p>The error is: "org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died"</p>
  
  <p>What do I need to do to regain control of the initial window? </p>
  
  <p>Thanks in advance.</p>