public void waitAndSwitchToNewBrowserWindow(int timeout) {
        final Set<String> handles = SenBotContext.getSeleniumDriver().getWindowHandles();
        mainWindowHandle.set(SenBotContext.getSeleniumDriver().getWindowHandles().iterator().next());

        if (getWebDriver() instanceof InternetExplorerDriver) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        String newWindow = (new WebDriverWait(getWebDriver(), timeout)).until(new ExpectedCondition<String>() {
            public String apply(WebDriver input) {
                if (input.getWindowHandles().size() > 1) {
                    Iterator<String> iterator = input.getWindowHandles().iterator();
                    String found = iterator.next();
                    found = iterator.next();
                    return found;
                }
                return null;
            }
        });

        assertTrue(!newWindow.equals(mainWindowHandle.get()));
        assertTrue(!newWindow.isEmpty());

        popupWindowHandle.set(newWindow);
        SenBotContext.getSeleniumDriver().switchTo().window(newWindow);
    }
public void waitAndSwitchToNewBrowserWindow ( int timeout ) { final Set < String > handles = SenBotContext . getSeleniumDriver ( ) . getWindowHandles ( ) ; mainWindowHandle . set ( SenBotContext . getSeleniumDriver ( ) . getWindowHandles ( ) . iterator ( ) . next ( ) ) ; if ( getWebDriver ( ) instanceof InternetExplorerDriver ) { try { Thread . sleep ( 1000 ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } String newWindow = ( new WebDriverWait ( getWebDriver ( ) , timeout ) ) . until ( new ExpectedCondition < String > ( ) { public String apply ( WebDriver input ) { if ( input . getWindowHandles ( ) . size ( ) > 1 ) { Iterator < String > iterator = input . getWindowHandles ( ) . iterator ( ) ; String found = iterator . next ( ) ; found = iterator . next ( ) ; return found ; } return null ; } } ) ; assertTrue ( ! newWindow . equals ( mainWindowHandle . get ( ) ) ) ; assertTrue ( ! newWindow . isEmpty ( ) ) ; popupWindowHandle . set ( newWindow ) ; SenBotContext . getSeleniumDriver ( ) . switchTo ( ) . window ( newWindow ) ; }
Waits for a new browser window to pop up and switches to it

@param timeout Timeout to wait for