2

I have a pop-up window that I have to handle after clicking a button on the Chrome browser. As soon as the popup is launched programmatically, any further action by the driver object results in this exception:

OpenQA.Selenium.WebDriverException: No response from server for url

Also there is no change in number of windowhandles list (driver.WindowHandles) after the pop-up window is launched. Please don't confuse this with switching windows in tabs.

Does Selenium ChromeDriver currently have support for handling pop-up windows?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
navger
  • 133
  • 1
  • 1
  • 9

1 Answers1

1

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);
    }

}
Johnny
  • 14,397
  • 15
  • 77
  • 118