0

Possible Duplicate:
display image from URL retrieved from ALAsset in iPhone

My code is:

Set<String> windowsid = driver.getWindowHandles();
Iterator<String> iterate = windowsid.iterator();

while(iterate.hasNext()){
    System.out.println(iterate.next());
}

String mainwindow_id = iterate.next();
String tabbedwindow_id = iterate.next();

I get an error @ String mainwindow_id = iterate.next();

Stating the below, Line 45 is the one i have in quotes.
I have declared the Set as String

Please Help !

Exception in thread "main" java.util.NoSuchElementException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:375)
at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:384)
at windows.traverse.main(traverse.java:45)
Community
  • 1
  • 1
Ram
  • 161
  • 2
  • 2
  • 10

2 Answers2

2

After the loop,

while(iterate.hasNext()){ 
    System.out.println(iterate.next()); 
} 

there are no elements left in the set to iterate. You iterated through all the windows and that's why NoSuchElementException.

Can you explain a little bit about what you want to do?

If I understand you correctly, you dont need to use a loop. Since there are only two windows, you can just do ..

Set<String> windowsid = driver.getWindowHandles();
Iterator<String> iterate = windowsid.iterator();

String mainwindow_id = iterate.next();
String tabbedwindow_id = iterate.next();
vidit
  • 6,293
  • 3
  • 32
  • 50
  • 1
    The above prints me the window which is opened. After printing me the 2 windows it throws error. Basically i wanted to click an link and that opens an dynamic window. So i wanna perform some actions and then switch back to main window. Instead of while loop I simply used iterate.next(); twice it didn't work. used implicit wait after click even then a big no to all :( – Ram Jul 06 '12 at 15:20
1

If loop has to be used then it's like

while(iterate.hasNext()){
    String st = iterate.next();
    System.out.println(st);
}
thegrinner
  • 11,546
  • 5
  • 41
  • 64
Ram
  • 161
  • 2
  • 2
  • 10