Multiple Windows handling in Webdriver
// Creating webdriver object
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://rediff.com");
// getWindowHandles method of driver class return a string
// this string is a unique key referencing all browsers/open
// opened by our webdriver, we save all values in a Set
Set<String> hs = driver.getWindowHandles();
// Iterating to the set and picking all available values
Iterator<String> iter = hs.iterator();
// Setting iterator to work until value exist there
while(iter.hasNext())
{
// Here we can perform different actions on window'
// here in code we are justr moving to there windows
// and closing all windows opened by webdriver
driver.switchTo().window((String) iter.next()).close();
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment