Handle Windows Switching in Selenium Web-driver

We can handle switching of windows in selenium web-driver using Switch To methods which will allow us to switch control from main window to sub/child window. In web applications most of time you must have faced this scenario where you must deal with multiple windows. Script example how to handle multiple windows in selenium web-driver.

import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Swtich_window_session {
public void TestingPopUp() throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“http://www.naukri.com/”);
String main_window=driver.getWindowHandle();
Sets1=driver.getWindowHandles();
Iterator I1= s1.iterator();
while(I1.hasNext()) {
String sub_window =I1.next();
if(!parent.equals(sub_window)) {
driver.switchTo().window(sub_window);
System.out.println(driver.switchTo().window(sub_window).getTitle());
driver.close();
} }
driver.switchTo().window(main_window);
}

}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top