title: automatic window close and switch back to parent window in selenium
body: <p>Basic I am using maven with POM and I am unable to switch focus back on parent window after I perform a operation in second window and click send window close automatically and after that my Firefox driver does not work .</p>
  
  <p>**I used three options mentioned below which are not working  **</p>
  
  <pre><code>    public void switchWindow() {
          String handle = driver.getWindowHandle();
          Set&lt;String&gt; set = driver.getWindowHandles();
          set.remove(handle);
          if (set.size() &gt;= 1) {
            driver.switchTo().window((String) set.toArray()[0]);
          }
  
  
    public WebDriver switchWindowByTitle(String title)
    {
        WebDriver popup = null;
        Set&lt;String&gt; windowIterator = driver.getWindowHandles();
        System.err.println("No of windows :  " + windowIterator.size());
        for (String s : windowIterator) {
            String windowHandle = s;
            popup = driver.switchTo().window(windowHandle);
            System.out.println("Window Title : " + popup.getTitle());
            System.out.println("Window Url : " + popup.getCurrentUrl());
            if (popup.getTitle().equals(title) ){
                System.out.println("Selected Window Title : " + popup.getTitle());
                return popup;
            }
  
        }
        System.out.println("Window Title :" + popup.getTitle());
        System.out.println();
        return popup;
  
  
   public WebDriver switchWindowByTitle(String title)
    {
  
   String currentWindow = driver.getWindowHandle();
      List&lt;String&gt; availableWindows = new ArrayList&lt;String&gt;(driver.getWindowHandles());
  
      for(String w : availableWindows)
      {
        if (w != currentWindow)
        {
          driver.switchTo().window(w);
          if (driver.getTitle().equalsIgnoreCase(title))
            return true;
          else
          {
            driver.switchTo().window(currentWindow);
          }
        }
      }
      return false;
    }
  </code></pre>