Question: I am working on a page which have some pop ups. I want to test all the HTML element availability on all the pop ups. SO to know current frame no. Is there any method available like `Selenium.getFrameNumber()` or something so that I can switch to required frames using 

```
Selenium.switchTo().frame(0);   or Selenium.switchTo().defaultContent();

```

Answer: 
In one project I made, I used a ArrayList to keep track of the windows.

```
List<String> windowList = new ArrayList<String>();
windowList.add( driver.getWindowHandle() );

```

The initial window always populates the first entry in the list and never changes.

Subsequent windows get added onto the END of the list like so:

```
driver.clickButtonToOpenPopup();
windowList.add( driver.getWindowHandle() );

```

Then, when a popup window (or windows) or tab is closed, I decrement the list in the order than I opened the windows.

```
  pos = windowList.size();
  if ( pos > 1 && driver.closeCurrentWindow() && windowList.remove() ) {
        log.info( "Closed window at position #" + pos );
  } else {
     log.info("There was a problem closing the window.");
  }

```

Lots of different ways you could do this.

If I were to do it again, I might use the [ArrayDeque class](https://docs.oracle.com/javase/7/docs/api/java/util/ArrayDeque.html).
There is no default option available for that, but you can get this in different ways,

Store the list of iframes in the page, 

```
List<WebElement> myIframes= driver.findElements(By.tagName("iframe"));

```

and you can iterate to get to the required frame with their id.

you can get the total no. of frames,

```
myIframes.size();

```