RE: driver.getWindowHandles() returns an unordered list.

Hello, driver.getWindowHandles() returns an unordered list. If I want to switch to a particular window based on its index(i.e, index = 0) , it is pointing to parent window(which is wrong window). It is supposed to a switch to first child window. I am facing this issue in IE Browser only. Can someone help me in finding solution for this issue.   Regards, Ramya

RamyaPasala Default Asked on February 14, 2017 in Selenium WebDriver.
Add Comment
1 Answers

Hi Ramya,

You can try this code.

 

WebDriver driver = new  FirefoxDriver();
String parentHandle = driver.getWindowHandle();   //get parent window handle
Set<String> windowHandles = driver.getWindowHandles();  // get all window handles
for(String window : windowHandles){
driver.switchTo().window(window);
if(driver.getTitle().equals(“your title”)){   // iterate this set untill you find your window
// perform operation
}
}
driver.switchTo().window(parentHandle);
}

 

Regards,
Ankit

Vice Professor Answered on February 14, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.