4

I am working with Selenium WebDriver to automate my companies site. At one point, the web application opens a new window via the following:

<a onclick="WindowController.openWindow('quote.action?quoteProcessName=Shortform',WindowController.WINDOW_IS_TRACKED);" tabindex="1">Express Quote</a>

we are using jQuery, though I think this is custom. I am on the test team, and don't do any of the development of the site. Anyway, it uses JavaScript to open a new window. After the script clicks this link, I need it to attach to the new window.

The problem is that WebDriver doesn't seem to find the new window when running in IE9. Here's the code I am using to try and switch to the new window:

public boolean switchTo(final WebRobot robot, final String pageTitle) {
    boolean found = false;

    int count = 0;
    while (!found && count < 20) {
        final Set<String> handles = robot.getDriver().getWindowHandles();
        final Iterator<String> itr = handles.iterator();
        while (itr.hasNext()) {
            try {
                final String current = itr.next();
                robot.getDriver().switchTo().window(current);
                if (robot.getDriver().getTitle().contains(pageTitle)) {
                    robot.getLogger().debug("Switching to " + pageTitle);
                    found = true;
                }
            } catch (final NoSuchWindowException e) {
                count++;
                try {
                    Thread.sleep(2000);
                    System.out.println("Handles: " + robot.getDriver().getWindowHandles().size());
                } catch (final InterruptedException ignored) {
                    //Nothing to do here
                }
            }
        }
    }
    return found;
}

(WebRobot is a class that I wrote to allow me to easily switch browsers and execution modes with WebDriver. robot.getDriver() returns the Selenium WebDriver object.)

After the new window opens, robot.getDriver().getWindowHandles().size() is always 1. Is there something I am missing to pick up the new window?

This code works perfectly in Firefox, Chrome, and IE8, but not IE9. I am using the 64 bit edition of IEDriverServer, version 2.32.3.0. I am using Selenium WebDriver 2.32, and am running on Windows 7 64bit.

Merkidemis
  • 2,550
  • 2
  • 16
  • 26
  • Does your `System.out.println()` call **ever** show a window handle count > 1? I can understand it never finding the window, because you never refresh the contents of `handles` within the loop, so it will always have the set of window handles it was initialized with, which is potentially a single handle. – JimEvans Apr 25 '13 at 17:07
  • Updated the code to refresh the handles each iteration. Still only sees the original window. – Merkidemis Apr 25 '13 at 19:45
  • I can state categorically that the window detection is not broken globally, for all pages, everywhere. You can try increasing the verbosity of the IEDriverServer.exe logging (search the web for how to do that in your language of choice), or provide a complete sample that demonstrates the issue, including complete HTML pages. – JimEvans Apr 26 '13 at 14:02
  • Unfortunately I cannot provide HTML source. Company property and all that. Here is the log file though: http://www.redlightning.net/ieLog.txt – Merkidemis Apr 29 '13 at 20:03

2 Answers2

0

http://grokbase.com/t/gg/webdriver/128hgbmcw0/getwindowhandles-return-only-1-window-in-ie

newSet.removeAll(oldSet); newWindow = newSet.toArray()[0];

  • http://selenium.10932.n7.nabble.com/Unable-to-run-Selenium-tests-in-IE-Browser-td22982.html –  May 22 '13 at 10:12
  • The first link goes to a thread suggesting looping and waiting for the new window handle to appear, which I am already doing. Plus, later in the thread other users state they are still having the same issue. Second link tells me I need to use IEServerDriver, which I am already doing otherwise IE wouldn't even open. Thanks, but neither of these provide a solution. – Merkidemis May 23 '13 at 15:19
0

Turning on Compatibility Mode fixed the issue.

Merkidemis
  • 2,550
  • 2
  • 16
  • 26