Search This Blog

August 11, 2016

How to handle multiple windows in Selenium?

If new members work on automated tests via our Selenium test framework, the common question they have is how to handle the additional window popbox if we click the url in the current window ?

It is pretty easy.  Using the following C # code works perfectly.

                      var windows = _driver.WindowHandles;
                    _driver.SwitchTo().Window(windows[1]);

                      // do something such as Assertion.
                    _driver.Close(); 
                    _driver.SwitchTo().Window(windows[0]);

No comments: