当前位置: 首页>>代码示例>>C#>>正文


C# IWebDriver.GetWindowHandles方法代码示例

本文整理汇总了C#中IWebDriver.GetWindowHandles方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.GetWindowHandles方法的具体用法?C# IWebDriver.GetWindowHandles怎么用?C# IWebDriver.GetWindowHandles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWebDriver的用法示例。


在下文中一共展示了IWebDriver.GetWindowHandles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SelectBlankWindow

        /**
         * Selects the only <code>_blank</code> window. A window open with
         * <code>target='_blank'</code> will have a <code>window.name = null</code>.
         * <p/>
         * <p>This method assumes that there will only be one single
         * <code>_blank</code> window and selects the first one with no name.
         * Therefore if for any reasons there are multiple windows with
         * <code>window.name = null</code> the first found one will be selected.
         * <p/>
         * <p>If none of the windows have <code>window.name = null</code> the last
         * selected one will be re-selected and a {@link SeleniumException} will
         * be thrown.
         *
         * @throws NoSuchWindowException if no window with
         *                               <code>window.name = null</code> is found.
         */
        public void SelectBlankWindow(IWebDriver driver)
        {
            string current = driver.GetWindowHandle();

            // Find the first window without a "name" attribute
            ReadOnlyCollection<string> handles = driver.GetWindowHandles();
            foreach (string handle in handles)
            {
                // the original window will never be a _blank window, so don't even look at it
                // this is also important to skip, because the original/root window won't have
                // a name either, so if we didn't know better we might think it's a _blank popup!
                if (handle == originalWindowHandle)
                {
                    continue;
                }

                driver.SwitchTo().Window(handle);
                string value = ((IJavaScriptExecutor)driver).ExecuteScript("return window.name;").ToString();
                if (string.IsNullOrEmpty(value))
                {
                    // We found it!
                    return;
                }
            }

            // We couldn't find it
            driver.SwitchTo().Window(current);
            throw new SeleniumException("Unable to select window _blank");
        }
开发者ID:hugs,项目名称:selenium,代码行数:45,代码来源:WindowSelector.cs

示例2: HandleSeleneseCommand

        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            string current = driver.GetWindowHandle();

            List<string> attributes = new List<string>();
            foreach (string handle in driver.GetWindowHandles())
            {
                driver.SwitchTo().Window(handle);
                attributes.Add(driver.Title);
            }

            driver.SwitchTo().Window(current);

            return attributes.ToArray();
        }
开发者ID:hugs,项目名称:selenium,代码行数:15,代码来源:GetAllWindowTitles.cs

示例3: HandleSeleneseCommand

        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            string current = driver.GetWindowHandle();

            List<string> attributes = new List<string>();
            foreach (string handle in driver.GetWindowHandles())
            {
                driver.SwitchTo().Window(handle);
                string attributeValue = (string)((IJavaScriptExecutor)driver).ExecuteScript("return '' + window[arguments[0]];", value);
                attributes.Add(attributeValue);
            }

            driver.SwitchTo().Window(current);

            return attributes.ToArray();
        }
开发者ID:zerodiv,项目名称:CTM-Windows-Agent,代码行数:16,代码来源:GetAttributeFromAllWindows.cs

示例4: SelectWindowWithTitle

        private static void SelectWindowWithTitle(IWebDriver driver, string title)
        {
            bool windowSuccessfullySwitched = false;
            string current = driver.GetWindowHandle();
            foreach (string handle in driver.GetWindowHandles())
            {
                driver.SwitchTo().Window(handle);
                if (title == driver.Title)
                {
                    windowSuccessfullySwitched = true;
                    break;
                }
            }

            if (!windowSuccessfullySwitched)
            {
                driver.SwitchTo().Window(current);
                throw new SeleniumException("Unable to select window with title: " + title);
            }
        }
开发者ID:hugs,项目名称:selenium,代码行数:20,代码来源:WindowSelector.cs


注:本文中的IWebDriver.GetWindowHandles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。