Пример #1
0
        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);
        }
Пример #2
0
 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
 }
Пример #3
0
 private void SwitchTo(string windowName)
 {
     seleniumWindowManager.SwitchToWindow(windowName);
 }