I’m still new to C# programming and have been able to get WebDriver working properly to do much of the work I need to do on our site, except when new windows are launched. Seems there are a lot of options to handle this within Java, but I can’t seem to make the leap to C# in how to collect the Window Handles and then switch to the newly spawned one. Part of the problem I am facing is that since it takes a few seconds for the new window to populate I am trying a wait to be able to capture the new window. When I originally did this I tried using
wait.Until(WebDriver => driver.Title.Equals("_blank"));
driver.SwitchTo().Window("_blank")
to make sure the Window is spawned before trying to switch to it.
Then reading more on this I found I had to capture the windowHandles before making the switch, and since I still need to wait for the Window to spawn and populate I guess I need some kind of while to check for the new handle and switch to it, and at that point I am not sure what to do.
I’m using selenium2’s .Net WebDriver, with SpecFlow so all the tests are in C# and I feel more comfortable in doing C# than Java, though I have not done much advanced work with C#. If anyone has some tips to get me started on how to resolve this I’d appreciate it.
The .NET support classes in WebDriver.Support.dll have a PopupWindowFinder class designed to help exactly this scenario. It’s listed as experimental at the moment, but at the very least, you could examine the code of that class to see how it works. It might give you some insights on how to code your own, if it doesn’t exactly meet your needs.