--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
Something like this should work. BTW I used to work at fatwire; small world.
//Get current windows
final Set<String> beforeHandles = driver.getWindowHandles();
element.click(); //click action that cause new window to open
//wait for the new window to open
new WebDriverWait(driver, 30){
}.until(new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver) {
return (driver.getWindowHandles().size() > beforeHandles.size()) ? true : false;
}});
//Get after handles
Set<String> afterHandles = driver.getWindowHandles();
//remove all before handles from after. Leaves you with new window handle
afterHandles.removeAll(beforeHandles);
//Switch to the new window
String newWindowHandle = afterHandles.iterator().next();
driver.switchTo().window(newWindowHandle);