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 :
driver.get('http://www.naukri.com/')
WebDriverWait(driver,15).until(lambda d: len(driver.window_handles)==3)
print(driver.title)
driver.switch_to.window(driver.window_handles[1])
print(driver.title)
driver.switch_to.window(driver.window_handles[2])
print(driver.title)`
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:
driver.switch_to.window(handle)
But since the window name changes every time the page loads, this becomes unusable.
I also tried this :
list1=[]
list1=driver.window_handles
for x in list1:
print(driver.title)
but this prints the first window title three times instead. What should be my approach here?