Sign up ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I came across many solutions for switching between windows, one of them is:

Set<String> allWindows = driver.getWindowHandles();
for(String currentWindow : allWindows){

But, I am unable to go to a particular window. Can someone tell me how to switch to 3rd window from parent window (using java client library)?

share|improve this question
Good answer here:… There is no way to identify child/parent windows, but you can identify them by title/url/etc. – Sam Woods Sep 26 '13 at 18:00

2 Answers 2

The solution I would use is the WebDriver's driver.switchTo().frame() method but avoiding the index number.

You can select the window you want using;

  1. A number. (0 based index normally but NOT always with IE)
  2. A name or ID.
  3. A previously found WebElement.

An example:

share|improve this answer
File file = new File("G:\\Selenium\\All_Jars\\chromedriver.exe");
System.setProperty("",file.getAbsolutePath() );
driver = new ChromeDriver();

//Maximize the window       


//Get all window handles
Set<String> allHandles = driver.getWindowHandles();

//count the handles Here count is=2
System.out.println("Count of windows:"+allHandles.size());      

//Get current handle or default handle
String currentWindowHandle = allHandles.iterator().next();
System.out.println("currentWindow Handle"+currentWindowHandle);

//Remove first/default Handle

//get the last Window Handle
String lastHandle = allHandles.iterator().next();
System.out.println("last window handle"+lastHandle);

//switch to second/last window, because we know there are only two windows 1-parent window 2-other window(ad window)
share|improve this answer
Given the age of this question, it would help if you added an explanation that isn't in your code. Also, your solution will not be particularly reliable unless there are two and only two windows, and does not answer the OPs question of finding a specific window. – Kate Paulk May 21 at 11:25

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.