1st get the address of all the browsers using
Iterator<String> windows = driver.getWndowHandles().iterator();
Now suppose you want to close the window whose title is "abc";
while(windows.next()){
driver.switchTo().window(windows.next());
String title = driver.getTitle();
if(title.equals("abc")){
driver.close();
break;
}
}
or say if you want to close 3rd one by force and you don't know the expected title then
for(int i=0; i<3; i++){
driver.switchTo().window(windows.next());
if(i==2){
driver.close();
break;
}
}
or you can do the same -
for(int i=0; i<3; i++){
String child = windows.next();
if(i==2){
driver.switchTo().window(child);
driver.close();
break;
}
}
Iterator<String> windows = driver.getWndowHandles().iterator();
Now suppose you want to close the window whose title is "abc";
while(windows.next()){
driver.switchTo().window(windows.next());
String title = driver.getTitle();
if(title.equals("abc")){
driver.close();
break;
}
}
or say if you want to close 3rd one by force and you don't know the expected title then
for(int i=0; i<3; i++){
driver.switchTo().window(windows.next());
if(i==2){
driver.close();
break;
}
}
or you can do the same -
for(int i=0; i<3; i++){
String child = windows.next();
if(i==2){
driver.switchTo().window(child);
driver.close();
break;
}
}
No comments:
Post a Comment