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


C# ISession.AddUIElement方法代码示例

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


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

示例1: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);

            AutomationElement start = null;
            if (urlParams.ContainsKey("id"))
            {
                start = session.GetUIElement(int.Parse(urlParams["id"]));
            }
            else
            {
                start = session.FocusOnCurrentWindow ?
                    this.uiAutomation.GetFocusedWindowOrRoot() :
                    AutomationElement.RootElement;
            }

            IEnumerable elements = null;
            if (request.Strategy == "xpath")
            {
                elements = this.uiAutomation.FindAllByXPath(start, request.Locator);
            }
            else
            {
                var property = AutomationElement.AutomationIdProperty;
                object locator = request.Locator;

                if (request.Strategy == "name")
                {
                    property = AutomationElement.NameProperty;
                }
                else if (request.Strategy == "class name")
                {
                    property = AutomationElement.ClassNameProperty;
                }
                else if (request.Strategy == "id")
                {
                    property = AutomationElement.AutomationIdProperty;
                }
                else if (request.Strategy == "tag name")
                {
                    property = AutomationElement.ControlTypeProperty;
                    locator = this.uiAutomation.FromTagName(request.Locator);
                }

                elements = start.FindAll(
                    TreeScope.Descendants,
                    new PropertyCondition(property, locator));
            }

            var list = new List<Dictionary<string, string>>();
            foreach (AutomationElement element in elements)
            {
                int id = session.AddUIElement(element);
                list.Add(new Dictionary<string, string> { { "ELEMENT", id.ToString() } });
            }

            return list;
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:58,代码来源:FindElementsHandler.cs

示例2: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);

            AutomationElement start = null;
            if (urlParams.ContainsKey("id"))
            {
                start = session.GetUIElement(int.Parse(urlParams["id"]));
            }
            else
            {
                start = session.FocusOnCurrentWindow ?
                    this.uiAutomation.GetFocusedWindowOrRoot() :
                    AutomationElement.RootElement;
            }

            AutomationElement element = null;
            if (request.Strategy == "xpath")
            {
                element = this.uiAutomation.FindFirstByXPath(start, request.Locator);
            }
            else
            {
                // TODO throw exceptions to indicate other strategies are not supported.
                var property = AutomationElement.AutomationIdProperty;
                object locator = request.Locator;

                if (request.Strategy == "name")
                {
                    property = AutomationElement.NameProperty;
                }
                else if (request.Strategy == "class name")
                {
                    property = AutomationElement.ClassNameProperty;
                }
                else if (request.Strategy == "id")
                {
                    property = AutomationElement.AutomationIdProperty;
                }
                else if (request.Strategy == "tag name")
                {
                    property = AutomationElement.ControlTypeProperty;
                    locator = this.uiAutomation.FromTagName(request.Locator);
                }

                element = start.FindFirst(
                    TreeScope.Descendants,
                    new PropertyCondition(property, locator));
            }

            if (element == null)
            {
                throw new NoSuchElementException(request.Strategy, request.Locator);
            }

            int id = session.AddUIElement(element);
            return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:58,代码来源:FindElementHandler.cs

示例3: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var element = this.uiAutomation.FocusedElement;

            this.overlay.Clear();
            this.overlay.HighlightedElement = element;
            this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);

            int id = session.AddUIElement(element.AutomationElement);
            return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:11,代码来源:ActiveElementHandler.cs

示例4: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var request = JsonConvert.DeserializeObject<FindElementsRequest>(body);

            IElement context = null;
            if (urlParams.ContainsKey("id"))
            {
                context = this.elementFactory.GetElement(
                    session.GetUIElement(int.Parse(urlParams["id"])));
            }
            else
            {
                context = this.elementFactory.GetElement(
                    session.FocusOnCurrentWindow ?
                    this.uiAutomation.GetFocusedWindowOrRoot() :
                    AutomationElement.RootElement);
            }

            IList<IElement> elements = null;
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            do
            {
                elements = this.searcher.FindAll(context, request.Strategy, request.Locator);
            }
            while (elements.Count == 0 && stopwatch.ElapsedMilliseconds < session.ImplicitWaitMillis);

            this.overlay.Clear();
            this.overlay.ContextElement = context;
            this.overlay.HighlightedElements = elements;
            this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);

            var list = new List<Dictionary<string, string>>();
            foreach (IElement element in elements)
            {
                int id = session.AddUIElement(element.AutomationElement);
                list.Add(new Dictionary<string, string> { { "ELEMENT", id.ToString() } });
            }

            return list;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:41,代码来源:FindElementsHandler.cs

示例5: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);

            IElement context = null;
            if (urlParams.ContainsKey("id"))
            {
                context = this.elementFactory.GetElement(
                    session.GetUIElement(int.Parse(urlParams["id"])));
            }
            else
            {
                context = this.elementFactory.GetElement(
                    session.FocusOnCurrentWindow ?
                    this.uiAutomation.GetFocusedWindowOrRoot() :
                    AutomationElement.RootElement);
            }

            IElement element = null;
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            do
            {
                element = this.searcher.FindFirst(context, request.Strategy, request.Locator);
            }
            while (element == null && stopwatch.ElapsedMilliseconds < session.ImplicitWaitMillis);

            this.overlay.Clear();
            this.overlay.ContextElement = context;
            this.overlay.HighlightedElement = element;
            this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);

            if (element == null)
            {
                throw new NoSuchElementException(request.Strategy.ToString(), request.Locator);
            }

            int id = session.AddUIElement(element.AutomationElement);
            return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:40,代码来源:FindElementHandler.cs


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