We are working with Selenium webdriver to make UI tests for Internet Explorer 11. In the tested webapplication there are several screens popping up. In several tests we end up with three browserswindows, so also three Driver.WindowHandles. To switch from one WindowHandle to the other we expected that Driver.WindowHandles would be sorted like the oldest windows first and the newest windows last. But this is not the case: It is totaly random!
Because a windowhandle is a GUID we ended up creating a dictionary with the WindowHandle GUID as key with the value of the type of page which is loaded in the browserwindow. But this also results in maintaining the dictionary when closing a window for instance.
This seems to be a lot of work for such a simple matter. Is there a better solution for this?
You are pretty correct when you say:
In a discussion, Simon clearly mentioned that:
So, we will induce an
WebDriverWait
and then collect the window handles every time we open a new tab/window and finally iterate through the window handles andswitchTo().window(newly_opened)
as required:Java:
Console Output:
Outro
You can find the python based discussion in Open web in new tab Selenium + Python