Sunday 10 July 2022

How To Switch Windows in Selenium Java | How To Handle Window in Selenium Webdriver

                  In this post, we will see How To Switch Windows in Selenium Java | How To Handle Window in Selenium Webdriver 

Program Code (

package main;

import java.time.Duration;

import java.util.Iterator;

import java.util.Set;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;


public class SwitchWindows {

public static void main(String[] args) {

System.setProperty("", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();




driver.findElement(By.xpath("//button[@aria-label='Confirmation. Get your favourite food at your train seat through <a class=\"txt-msg-info\" target=\"_blank\" href=\"\">e-Catering</a> available at selected stations.<br/><br/>COVID 19 Alert:<br/><br/><i class=\"fa fa-circle\" ></i> All passengers are advised to wear face covers/masks at the entry/exit and during travel.<br/><br/><i class=\"fa fa-circle\" ></i> All passengers are advised that on arrival at their destination, the travelling passenger shall follow the Covid protocol/guidelines issued by Ministry of Home affairs, Ministry of Health and Family Welfare and concerned State/UTs on the subject from time to time.<br/><br/><i class=\"fa fa-circle\" ></i><a class=\"txt-msg-info\"target=\"_blank\"href=\"\"> Information on Covid 19 Vaccination Programme</a>. Press OK to confirm']")).click();

driver.findElement(By.xpath("//span[@class='allcircle circletwo']")).click();

Set<String> handles=driver.getWindowHandles(); //parentid,childid,subchildid

Iterator it=handles.iterator();

String parentid=(String);

String childid=(String);


driver.findElement(By.xpath("//div[@class='Nav-icons BusTickets']")).click();



Watch following video:

Watch on YouTube:

1 comment: