So my question deals with iterating over multiple open windows at a time. Suppose I am opening a website (best example would be Naukri).

As soon as the page loads, two more pop up windows open up. My thought was to iterate on these open windows and get the title of each one of them.

Here is what I wrote :


    WebDriverWait(driver,15).until(lambda d: len(driver.window_handles)==3)




Now my question is that- this works, as far as we know that three windows are active. In this case, we don't know the exact number, how are we going to iterate through them? I thought of using this:

for handle in driver.window_handles:

But since the window name changes every time the page loads, this becomes unusable.

I also tried this :


for x in list1:

but this prints the first window title three times instead. What should be my approach here?


you need to switch to desired window before printing the title:

handles = driver.window_handles
for ii, hh in enumerate( handles ):
    print 'window %s has title %s' % (ii, driver.title)
| improve this answer | |
  • not sure if I understand the last i. I tried the list one with i and it says list can't have str indices. – demouser123 Jun 25 '15 at 15:16
  • variable i was loop counter. I wrote whole loop for you – Peter M. - stands for Monica Jun 25 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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