[英]Selenium IEServerDriver not finding new windows for IE9
I am working with Selenium WebDriver to automate my companies site. 我正在与Selenium WebDriver合作,以自动化我的公司网站。 At one point, the web application opens a new window via the following:
有一次,Web应用程序通过以下方式打开一个新窗口:
<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. 我们正在使用jQuery,虽然我认为这是自定义的。 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.
无论如何,它使用JavaScript打开一个新窗口。 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. 问题是WebDriver在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.) (WebRobot是我编写的一个类,允许我使用WebDriver轻松切换浏览器和执行模式.robot.getDriver()返回Selenium WebDriver对象。)
After the new window opens, robot.getDriver().getWindowHandles().size() is always 1. Is there something I am missing to pick up the new window? 新窗口打开后,robot.getDriver()。getWindowHandles()。size()始终为1.是否有一些我缺少的东西来拿起新窗口?
This code works perfectly in Firefox, Chrome, and IE8, but not IE9. 此代码在Firefox,Chrome和IE8中完美运行,但不适用于IE9。 I am using the 64 bit edition of IEDriverServer, version 2.32.3.0.
我使用的是64位版本的IEDriverServer,版本2.32.3.0。 I am using Selenium WebDriver 2.32, and am running on Windows 7 64bit.
我使用的是Selenium WebDriver 2.32,我在Windows 7 64bit上运行。
http://grokbase.com/t/gg/webdriver/128hgbmcw0/getwindowhandles-return-only-1-window-in-ie http://grokbase.com/t/gg/webdriver/128hgbmcw0/getwindowhandles-return-only-1-window-in-ie
newSet.removeAll(oldSet); newSet.removeAll(oldSet); newWindow = newSet.toArray()[0];
newWindow = newSet.toArray()[0];
启用兼容模式解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.