Selenium IEServerDriver找不到IE9的新窗口 [英] Selenium IEServerDriver not finding new windows for IE9

查看:261
本文介绍了Selenium IEServerDriver找不到IE9的新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium WebDriver来自动化公司网站.一方面,Web应用程序通过以下方式打开一个新窗口:

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

我们正在使用jQuery,尽管我认为这是自定义的.我在测试团队中,不做任何网站开发.无论如何,它使用JavaScript打开一个新窗口.脚本单击此链接后,我需要将其附加到新窗口.

问题在于,在IE9中运行时,WebDriver似乎找不到新窗口.这是我用来尝试切换到新窗口的代码:

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是我编写的一个类,允许我使用WebDriver轻松切换浏览器和执行模式.robot.getDriver()返回Selenium WebDriver对象.)

在打开新窗口之后,robot.getDriver().getWindowHandles().size()始终为1.

此代码可在Firefox,Chrome和IE8(而不是IE9)中完美运行.我使用的是IEDriverServer的64位版本,版本2.32.3.0.我正在使用Selenium WebDriver 2.32,并且正在Windows 7 64bit上运行.

解决方案

打开兼容模式可解决此问题.

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.

解决方案

Turning on Compatibility Mode fixed the issue.

这篇关于Selenium IEServerDriver找不到IE9的新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆