@Override
  public Windows getWindows() {

    Windows ret = new Windows();
    WebDriver d = getDriver();
    ret.setCurrent(d.getWindowHandle());
    ret.setAll(d.getWindowHandles());
    return ret;
  }
 @Override
 public void closeWindow(String handle) {
   Windows win = getWindows();
   LOGGER.debug("closeWindow: handle=" + handle + ", windows=" + win);
   if (!win.isCurrentWindow(handle)) {
     switchToWindow(handle);
     getDriver().close();
     switchToAnyOtherWindow(win);
   } else {
     closeCurrentWindow();
   }
 }
 private String switchToAnyOtherWindow(Windows win) {
   for (String handle : win.getNonCurrentWindows()) {
     try {
       switchToWindow(handle);
       return handle;
     } catch (NoSuchWindowException ex) {
       LOGGER.debug("switchToAnyOtherWindow: window does not exist: " + handle);
     }
   }
   return null;
 }
  @Override
  public String waitForNewWindow(final Windows windows, int seconds) {
    WebDriver d = getDriver();
    LOGGER.debug("waitForNewWindow: existing=" + windows.getAll());
    waitFor(
        seconds,
        new ExpectedCondition<Boolean>() {
          public Boolean apply(WebDriver d) {
            return (d.getWindowHandles().size() > windows.getAll().size());
          }
        });
    Set<String> handles = d.getWindowHandles();
    LOGGER.debug("waitForNewWindow: handles=" + handles);

    handles.removeAll(windows.getAll());
    if (handles.size() > 0) {
      String handle = handles.iterator().next();
      LOGGER.debug("waitForNewWindow: found new window - handle=" + handle);
      return handle;
    }
    LOGGER.debug("waitForNewWindow: did not find new window");
    return null;
  }