How to Handle Multiple Windows in Selenium Webdriver using Java


              Multiple Windows Handling in Selenium  

How to Handle Multiple Windows in Selenium?

How to handle Child window in selenium?

Selenium Code - 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
public class MultipleWindow 
public static void main(String[] args
// TODO Auto-generated method stub
System.setProperty("", "C:\\Software\\ChromeDriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
        // This statement will Open new window 
       //Get handles of the windows
         String mainWindowHandle = driver.getWindowHandle();
         Set<String> allWindowHandles = driver.getWindowHandles();
         Iterator<String> iterator = allWindowHandles.iterator();
         // This Statement will check if child window has other child windows and will fetch the heading of the child window
         while (iterator.hasNext()) 
             String ChildWindow =;
                 if (!mainWindowHandle.equalsIgnoreCase(ChildWindow)) 
                 WebElement text = driver.findElement("sampleHeading"));
                 System.out.println("Handling Child Window " + text.getText());






Hope!!! Above Tutorial of how to handle multiple windows in selenium helpful for you ...

QA acharya

How to handle multiple windows in selenium 

Post a Comment