public IEnumerable <string> FindWindowHandles(string titleOrName, Options options) { var currentHandle = GetCurrentWindowHandle(); IList <string> matchingWindowHandles = new List <string>(); try { _seleniumWindowManager.SwitchToWindow(titleOrName); matchingWindowHandles.Add(_webDriver.CurrentWindowHandle); } catch (NoSuchWindowException) { foreach (var windowHandle in _webDriver.WindowHandles) { _seleniumWindowManager.SwitchToWindow(windowHandle); if (options.TextPrecisionExact) { if (ExactMatch(titleOrName, windowHandle)) { matchingWindowHandles.Add(windowHandle); } } else { if (SubstringMatch(titleOrName)) { matchingWindowHandles.Add(windowHandle); } } } } try { _seleniumWindowManager.SwitchToWindow(currentHandle); } catch (NoSuchWindowException ex) { throw new MissingWindowException("The active window was closed. Coypu should prevent this by ensuring fresh scope higher up.", ex); } return(matchingWindowHandles); }
private void AcceptAnyAlert() { try { seleniumWindowManager.SwitchToWindow(webDriver.WindowHandles[0]); webDriver.SwitchTo().Alert().Accept(); } catch (WebDriverException) {} catch (KeyNotFoundException) {} // Chrome catch (InvalidOperationException) {} catch (IndexOutOfRangeException) {} // No window handles }
private void SwitchTo(string windowName) { seleniumWindowManager.SwitchToWindow(windowName); }