Treating pop-up window is the same as treating number of windows.
Try to do:
driver().switchTo().window((String)driver.getWindowHandles().toArray()[index]);
Where index is the index of the new window (can be passed as an argument in appropriate switch-window function).
Later, you can implement it in more clean way such as:
*In our case the webdriver is warped in WebDriverProxy object.
public static void switchFocusToWindowNumber(int index, WebDriverProxy webDriverProxy) {
try {
webDriverProxy.getWebDriver().switchTo().window((String) webDriverProxy.getWebDriver().getWindowHandles().toArray()[index]);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ArrayIndexOutOfBoundsException("ArrayIndexOutOfBoundsException: Number of open windows is: "
+ getNumberofWindows(webDriverProxy) + " Trying to close window number: " + index + "\n Exception: " + e);
} catch (NoSuchWindowException e) {
throw new NoSuchWindowException ("NoSuchWindowException: Number of windows is: " + getNumberofWindows(webDriverProxy) +
" Trying to close window number: " + index + "\n Exception: " + e);
}
}