code: private void switchToWindow(String key, String handleToKeep) {
          Context.addWindow(key, handleToKeep);
          Context.setMainWindow(key);
          Context.getDriver().switchTo().window(handleToKeep);
      }
docs: switchToWindow switch to an other Window.