Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

java - Selenium IEServerDriver not finding new windows for IE9

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...