示例#1
0
        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() }
            });
        }
示例#2
0
        public IWebElement FindElementByCssSelector(string cssSelector)
        {
            var request = new FindElementRequest()
            {
                CssSelector = cssSelector
            };
            var response = Post <FindElementRequest, FindElementResponse>(request);

            if (!response.IsValid())
            {
                throw new Exception("Could not find element: Invalid response");
            }

            if (!response.ElementId.HasValue)
            {
                throw new Exception("Element not found");
            }

            return(new MyWebElement(this, response.ElementId.Value));
        }