How do you handle Multiple windows in your application?

Answers were Sorted based on User's Feedback

How do you handle Multiple windows in your application?..

Answer / deepa

driver.findElement(“id of the link which opens new window”)).click();

//wait till two windows are not opened

waitForNumberofWindowsToEqual(2);//this method is for wait

Set handles = driver.getWindowHandles();

firstWinHandle = driver.getWindowHandle(); handles.remove(firstWinHandle);

String winHandle=handles.iterator().next();

if (winHandle!=firstWinHandle){

//To retrieve the handle of second window, extracting the handle which does not match to first window handle

secondWinHandle=winHandle; //Storing handle of second window handle

//Switch control to new window


Is This Answer Correct ?    4 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / suresh777

Set<String> parent=driver.getWindowHandles();

Object[] child=parent.toArray();

driver.switchTo().window((String) child[1]);

Here we have handle at any number of Windows

Is This Answer Correct ?    2 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / chetan phani.j

We handle Multiple popups by using getwindowhandles().

Is This Answer Correct ?    0 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / jameel shaik

static WebDriver driver;
public void Window_Handle() throws InterruptedException
driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Actions a=new Actions(driver);
driver.findElement(By.linkText("Learn more")).click();
String ParentWindow=driver.getWindowHandle();
System.out.println("Before Opening The Site"+driver.getTitle());
Set<String> ChildWindow=driver.getWindowHandles();
System.out.println("Before Opening The Site"+ driver.getTitle());

Iterator<String> it=ChildWindow.iterator();

System.out.println("Getting Child Window Title After Opening"+ driver.getTitle());
System.out.println("After Opening The Site" +driver.getTitle());


Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Selenium Interview Questions

How can we launch different browsers in selenium webdriver?

0 Answers  

Write the code for reading and writing to excel through selenium?

0 Answers  

Explain what is datadriven framework and keyword driven?

0 Answers  

What is robot api?

0 Answers  

How to check which option in the dropdown is selected?

0 Answers  

What is a framework?

1 Answers  

How to create batch(.bat) file after creating suite from TestNG?Can anyone explain entire process?

2 Answers   Cube Digi,

How to check whether a text is underlined or not?

0 Answers  

Tell me what kind of mouse actions can be performed in selenium?

0 Answers  

Explain the meaning of assertion in selenium and what are the types of assertion?

0 Answers  

What are the types of listeners in testng?

0 Answers  

What is the difference between assert and verify in selenium?

0 Answers