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


C# ISession.GetUIElement方法代码示例

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


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

示例1: Handle

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

            if (request.ID != null)
            {
                // TODO not visible? scroll into view
                var id = int.Parse(request.ID);
                var element = this.elementFactory.GetElement(session.GetUIElement(id));

                int x = 0, y = 0;
                if (request.XOffset == null)
                {
                    x = element.X + (element.Width / 2);
                    y = element.Y + (element.Height / 2);
                }
                else
                {
                    x = element.X + int.Parse(request.XOffset);
                    y = element.Y + int.Parse(request.YOffset);
                }

                this.mouse.MoveTo(x, y);
            }
            else
            {
                // relative to current position of the mouse
                int x = int.Parse(request.XOffset);
                int y = int.Parse(request.YOffset);

                this.mouse.Move(x, y);
            }

            return null;
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:35,代码来源:MoveToHandler.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;
            }

            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

示例3: 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

示例4: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var id = int.Parse(urlParams["id"]);
            var element = this.elementFactory.GetElement(session.GetUIElement(id));

            element.Value = string.Empty;

            return null;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:9,代码来源:ClearTextHandler.cs

示例5: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var id = int.Parse(urlParams["id"]);
            var element = this.elementFactory.GetElement(session.GetUIElement(id));

            return new Dictionary<string, int?>
            {
                { "x", element.X },
                { "y", element.Y }
            };
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:11,代码来源:GetElementLocationHandler.cs

示例6: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var id = int.Parse(urlParams["id"]);
            var element = this.elementFactory.GetElement(session.GetUIElement(id));

            return new Dictionary<string, int>
            {
                { "width", element.Width },
                { "height", element.Height }
            };
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:11,代码来源:GetElementSizeHandler.cs

示例7: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var element = this.elementFactory.GetElement(session.GetUIElement(int.Parse(urlParams["id"])));
            var request = JsonConvert.DeserializeObject<ElementValueRequest>(body);

            var text = string.Join(string.Empty, request.KeySequence);

            element.SetFocus();
            this.keyboard.Type(text, session.Capabilities.KeystrokeDelay);

            return null;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:12,代码来源:SetElementValueHandler.cs

示例8: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var element = session.GetUIElement(int.Parse(urlParams["id"]));

            object objPattern;
            if (element.TryGetCurrentPattern(TextPattern.Pattern, out objPattern))
            {
                return ((TextPattern)objPattern).DocumentRange.GetText(-1);
            }

            return element.Current.Name;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:12,代码来源:GetElementTextHandler.cs

示例9: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var id = int.Parse(urlParams["id"]);
            var element = this.elementFactory.GetElement(session.GetUIElement(id));

            int x = element.X + (element.Width / 2);
            int y = element.Y + (element.Height / 2);

            this.mouse.MoveTo(x, y);
            this.mouse.Click(MouseButton.Left);

            return null;
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:13,代码来源:ClickElementHandler.cs

示例10: Handle

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

            if (request.ID != null)
            {
                // TODO not visible? scroll into view
                var id = int.Parse(request.ID);
                var element = this.elementFactory.GetElement(session.GetUIElement(id));

                if (!element.Bounds.HasValue)
                {
                    throw new FailedCommandException("Element's bounds are unknown.", 29); // InvalidElementCoordinates
                }

                int x = 0, y = 0;
                if (request.XOffset == null)
                {
                    x = element.X.Value + (element.Width.Value / 2);
                    y = element.Y.Value + (element.Height.Value / 2);
                }
                else
                {
                    x = element.X.Value + int.Parse(request.XOffset);
                    y = element.Y.Value + int.Parse(request.YOffset);
                }

                this.overlay.Clear();
                this.overlay.Target = new Point(x, y);
                this.overlay.ShowAndWait(session.Capabilities.OverlayTargetDelay);

                this.mouse.MoveTo(x, y);
            }
            else
            {
                // relative to current position of the mouse
                int x = int.Parse(request.XOffset);
                int y = int.Parse(request.YOffset);

                Point pos = this.mouse.Position;
                this.overlay.Clear();
                this.overlay.Target = new Point(pos.X + x, pos.Y + y);
                this.overlay.ShowAndWait(session.Capabilities.OverlayTargetDelay);

                this.mouse.Move(x, y);
            }

            return null;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:49,代码来源:MoveToHandler.cs

示例11: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var element = session.GetUIElement(int.Parse(urlParams["id"]));

            object pattern;
            if (element.TryGetCurrentPattern(TogglePattern.Pattern, out pattern))
            {
                var state = ((TogglePattern)pattern).Current.ToggleState;
                return state != ToggleState.Off;
            }
            else
            {
                return false;
            }
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:15,代码来源:IsElementSelectedHandler.cs

示例12: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var element = session.GetUIElement(int.Parse(urlParams["id"]));
            var request = JsonConvert.DeserializeObject<ElementValueRequest>(body);

            var sb = new StringBuilder();
            foreach (var key in request.KeySequence)
            {
                sb.Append(key);
            }

            // TODO send keyboard strokes, as SendKeysHandler
            var value = sb.ToString();
            ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).SetValue(value);

            return null;
        }
开发者ID:leeaa,项目名称:winappdriver,代码行数:17,代码来源:SetElementValueHandler.cs

示例13: 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

示例14: 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

示例15: Handle

        public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
        {
            var id = int.Parse(urlParams["id"]);
            var element = this.elementFactory.GetElement(session.GetUIElement(id));

            if (!element.Visible)
            {
                throw new FailedCommandException("The element is not visible.", 11); // ElementNotVisible
            }

            int x = element.X.Value + (element.Width.Value / 2);
            int y = element.Y.Value + (element.Height.Value / 2);

            this.overlay.Clear();
            this.overlay.Target = new Point(x, y);
            this.overlay.ShowAndWait(session.Capabilities.OverlayTargetDelay);

            this.mouse.MoveTo(x, y);
            this.mouse.Click(MouseButton.Left);

            return null;
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:22,代码来源:ClickElementHandler.cs


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