Created
July 28, 2021 11:39
-
-
Save Jaimin180296/3474173fee506cce90aebb123fcf9d67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
driver.get("https://demoqa.com/browser-windows"); | |
// Open new child window within the main window | |
driver.findElement(By.id("tabButton")).click(); | |
//Get handles of the windows | |
String mainWindowHandle = driver.getWindowHandle(); | |
System.out.println("main" + mainWindowHandle); | |
Set<String> allWindowHandles = driver.getWindowHandles(); | |
Iterator<String> iterator = allWindowHandles.iterator(); | |
// Here we 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)) { | |
System.out.println("child" + ChildWindow); | |
driver.switchTo().window(ChildWindow); | |
WebElement text = driver.findElement(By.id("sampleHeading")); | |
System.out.println("Heading of child window is " + text.getText()); | |
Thread.sleep(2000); | |
driver.close(); | |
} | |
driver.switchTo().window(mainWindowHandle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment