code: public void selectBlankWindow(WebDriver driver) {
      String current = driver.getWindowHandle();
      // Find the first window without a "name" attribute
      List<String> handles = new ArrayList<>(driver.getWindowHandles());
      for (String handle : handles) {
        // the original window will never be a _blank window, so don't even look at it
        // this is also important to skip, because the original/root window won't have
        // a name either, so if we didn't know better we might think it's a _blank popup!
        if (handle.equals(originalWindowHandle)) {
          continue;
        }
        driver.switchTo().window(handle);
        String value = (String)
            ((JavascriptExecutor) driver).executeScript("return window.name;");
        if (value == null || "".equals(value)) {
          // We found it!
          return;
        }
      }
      // We couldn't find it
      driver.switchTo().window(current);
      throw new SeleniumException("Unable to select window _blank");
    }
docs: Selects the only <code>_blank</code> window. A window open with <code>target='_blank'</code>
  will have a <code>window.name = null</code>.
  <p>
  This method assumes that there will only be one single <code>_blank</code> window and selects
  the first one with no name. Therefore if for any reasons there are multiple windows with
  <code>window.name = null</code> the first found one will be selected.
  <p>
  If none of the windows have <code>window.name = null</code> the last selected one will be
  re-selected and a {@link SeleniumException} will be thrown.
  
  @param driver WebDriver
  @throws NoSuchWindowException if no window with <code>window.name = null</code> is found.