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 org.openqa.selenium.chrome.ChromeDriver;
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("webdriver.chrome.driver", "C:\\Software\\ChromeDriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
 driver.get("https://demoqa.com/browser-windows");
 
        // This statement will Open new window 
         driver.findElement(By.id("windowButton")).click();
 
       //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 = iterator.next();
                 if (!mainWindowHandle.equalsIgnoreCase(ChildWindow)) 
{
                 driver.switchTo().window(ChildWindow);
                 WebElement text = driver.findElement(By.id("sampleHeading"));
                 System.out.println("Handling Child Window " + text.getText());
             }
         }
     }
 
}

 

 

 

 


How 


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

Team,
QA acharya

Tags: Multiple window handling in selenium , Window handling in selenium Webdriver , Windows Handling in Selenium , How to switch window 

How to handle multiple windows in selenium 


Post a Comment

0 Comments