final Set<String> handles = driver.getWindowHandles();
driver.findElement(By.linkText("Monitor Groups")).click();
// It wasn't waiting for the popup to be loaded... bug in webdriver maybe? I'll have to ask....
String newWindow = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<String>() {
public String apply(WebDriver input) {
Set<String> newHandles = input.getWindowHandles();
newHandles.removeAll(handles);
if (newHandles.size() > 0) {
return newHandles.iterator().next();
}
return null;
}
});
driver.switchTo().window(newWindow);
// wait for the element to appear
WebElement element = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver input) {
return input.findElement(By.id("newMonitorGroup"));
}
});
This assumes that clicking the link will actually open a popup (new window) and that new window will have an ID "newMonitorGroup" inside of it.