naukri.com has multiple screen, Set is use for managing all screens thru iterator. getWindowHandles() is selenium function
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.Iterator;
import java.util.Set;
public class multipleWindows {
public static void main(String[] args) {a
// TODO Auto-generated method stub
WebDriver driver;a
System.setProperty("webdriver.chrome.driver", "C://Users//ylondhe//Documents//chromedriver.exe");
driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.naukri.com/");
String mainWindow=driver.getWindowHandle();
System.out.println("mainWebApp :" + mainWindow);
// It returns no. of windows opened by WebDriver and will return Set of Strings
Set<String> set =driver.getWindowHandles();
// Using Iterator to iterate with in windows
Iterator<String> itr= set.iterator();
System.out.println("OPen windowes count :" +set.size());
System.out.println("OPen windowes :" + set);
while(itr.hasNext()){
String childWindow=itr.next();
// Compare whether the main windows is not equal to child window. If not equal, we will close.
if(!mainWindow.equals(childWindow)){
driver.switchTo().window(childWindow);
System.out.println(driver.switchTo().window(childWindow).getTitle());
}
}
driver.close();
driver.quit();
}
}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.Iterator;
import java.util.Set;
public class multipleWindows {
public static void main(String[] args) {a
// TODO Auto-generated method stub
WebDriver driver;a
System.setProperty("webdriver.chrome.driver", "C://Users//ylondhe//Documents//chromedriver.exe");
driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.naukri.com/");
String mainWindow=driver.getWindowHandle();
System.out.println("mainWebApp :" + mainWindow);
// It returns no. of windows opened by WebDriver and will return Set of Strings
Set<String> set =driver.getWindowHandles();
// Using Iterator to iterate with in windows
Iterator<String> itr= set.iterator();
System.out.println("OPen windowes count :" +set.size());
System.out.println("OPen windowes :" + set);
while(itr.hasNext()){
String childWindow=itr.next();
// Compare whether the main windows is not equal to child window. If not equal, we will close.
if(!mainWindow.equals(childWindow)){
driver.switchTo().window(childWindow);
System.out.println(driver.switchTo().window(childWindow).getTitle());
}
}
driver.close();
driver.quit();
}
}