Exemple #1
0
        /// <summary>
        /// Find element in current element using it's ControlType and Name
        /// </summary>
        /// <param name="controlType"></param>
        /// <param name="elementName"></param>
        /// <returns></returns>
        public WinElement FindElementByTypeAndName(ControlType controlType, string elementName)
        {
            var strategy = new FindElementStrategy(By.TypeAndName, elementName)
            {
                ControlType = controlType
            };

            return(FindElement(strategy));
        }
Exemple #2
0
        public Element FindElementInElement(string sessionId, string elementId, FindElementStrategy strategy)
        {
            var session = GetSession(sessionId);
            var element = new Element {
                Id = session.FindElement(new Guid(elementId), strategy)
            };

            return(element);
        }
Exemple #3
0
        internal Guid?FindElementByAutomationId(AutomationElement parentElement, FindElementStrategy strategy)
        {
            var element = FindElement(parentElement,
                                      new PropertyCondition(AutomationElement.AutomationIdProperty, strategy.Selector));

            if (element.Item1 == Guid.Empty)
            {
                return(null);
            }
            Elements.Add(element.Item1, element.Item2);
            return(element.Item1);
        }
Exemple #4
0
        private WinElement FindElement(FindElementStrategy strategy)
        {
            var elementGuid = WebHelper.FindElement(this, strategy);

            if (elementGuid == null)
            {
                return(null);
            }

            var element = new WinElement(Driver, elementGuid);

            return(element);
        }
Exemple #5
0
        /// <summary>
        /// Send request to find element in current element
        /// </summary>
        /// <param name="root"></param>
        /// <param name="strategy"></param>
        /// <returns></returns>
        internal static Guid?FindElement(WinElement root, FindElementStrategy strategy)
        {
            using (var httpClient = new HttpClient())
            {
                var json = JsonConvert.SerializeObject(strategy);
                var data = new StringContent(json, Encoding.UTF8, "application/json");

                var responseMessage = httpClient.PostAsync($"{root.Driver.Uri}/session/{root.Driver.Guid}/element/{root.Guid}/element", data).Result;
                var result          = JsonConvert.DeserializeObject <Element>(responseMessage.Content.ReadAsStringAsync().Result);

                return(result.Id);
            }
        }
Exemple #6
0
        internal Guid?FindElement(FindElementStrategy strategy)
        {
            switch (strategy.By)
            {
            case By.Name:
                return(FindElementByName(strategy));

            case By.AutomationId:
                return(FindElementByAutomationId(strategy));

            case By.TypeAndName:
                return(FindElementByTypeAndName(strategy));

            default:
                throw new Exception($"Unable to find specified method for strategy: {strategy.By}");
            }
        }
Exemple #7
0
        internal Guid?FindElementByTypeAndName(AutomationElement parentElement, FindElementStrategy strategy)
        {
            Console.WriteLine("Searching for type and property name");
            var automationType = GetType(strategy.ControlType);
            var condition      = new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, automationType),
                new PropertyCondition(AutomationElement.NameProperty, strategy.Selector));

            var element = FindElement(parentElement, condition);

            if (element.Item1 == Guid.Empty)
            {
                return(null);
            }

            Elements.Add(element.Item1, element.Item2);
            return(element.Item1);
        }
Exemple #8
0
        internal Guid?FindElement(Guid parentElementId, FindElementStrategy strategy)
        {
            var parentElement = Elements[parentElementId];

            switch (strategy.By)
            {
            case By.Name:
                return(FindElementByNameInElement(parentElement, strategy));

            case By.AutomationId:
                return(FindElementByAutomationId(parentElement, strategy));

            case By.TypeAndName:
                return(FindElementByTypeAndName(parentElement, strategy));

            default:
                throw new Exception($"Unable to find specified method for strategy: {strategy.By}");
            }
        }
Exemple #9
0
        internal Guid?FindElementByNameInElement(AutomationElement parentElement, FindElementStrategy strategy)
        {
            try
            {
                Console.WriteLine($"Searching for {strategy.Selector} element in parent element");
                var element = FindElement(parentElement,
                                          new PropertyCondition(AutomationElement.NameProperty, strategy.Selector));
                if (element.Item1 == Guid.Empty)
                {
                    return(null);
                }

                Elements.Add(element.Item1, element.Item2);
                Console.WriteLine($"Element found");
                return(element.Item1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(Guid.Empty);
        }
Exemple #10
0
        /// <summary>
        /// Find element in current element using it's AutomationId
        /// </summary>
        /// <param name="automationId"></param>
        /// <returns></returns>
        public WinElement FindElementByAutomationId(string automationId)
        {
            var strategy = new FindElementStrategy(By.AutomationId, automationId);

            return(FindElement(strategy));
        }
Exemple #11
0
        /// <summary>
        /// Find element in current element using it's name
        /// </summary>
        /// <param name="elementName"></param>
        /// <returns></returns>
        public WinElement FindElementByName(string elementName)
        {
            var strategy = new FindElementStrategy(By.Name, elementName);

            return(FindElement(strategy));
        }
Exemple #12
0
        internal Guid?FindElementByTypeAndName(FindElementStrategy strategy)
        {
            var session = Elements[SessionId];

            return(FindElementByTypeAndName(session, strategy));
        }
Exemple #13
0
        internal Guid?FindElementByAutomationId(FindElementStrategy strategy)
        {
            var session = Elements[SessionId];

            return(FindElementByAutomationId(session, strategy));
        }