I work with Selenium WebDriver to automate the site of my companies. At some point, the web application opens a new window through the following:
<a onclick="WindowController.openWindow('quote.action?quoteProcessName=Shortform',WindowController.WINDOW_IS_TRACKED);" tabindex="1">Express Quote</a>
we use jQuery, although I think this is custom. I am in the test team and do not develop the site. Anyway, it uses JavaScript to open a new window. After the script clicks this link, I need it to be attached to a new window.
The problem is that WebDriver does not seem to find a new window when working in IE9. Here is the code I use to try moving to a 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) {
}
}
}
}
return found;
}
(WebRobot - , , WebDriver. robot.getDriver() Selenium WebDriver.)
robot.getDriver(). getWindowHandles(). size() 1. -, , ?
Firefox, Chrome IE8, IE9. 64- IEDriverServer, 2.32.3.0. Selenium WebDriver 2.32 64- Windows 7.