Esempio n. 1
0
        /// <summary>
        ///     Gets the first result for the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="timeout">The maximum amount of time to wait for the required element to become available.</param>
        /// <returns>The automation element.</returns>
        public override AutomationElement GetFirstResult(Query query, TimeSpan timeout)
        {
            Debug.WriteLine("FirstResult - " + query, "UIAutomation-SearchEngine-TreeWalker");

            var root       = query.Root;
            var scope      = query.Scope;
            var conditions = query.Conditions;
            // The callback for return matched elements.
            var returnMatchedChild = new WithElementCallback(child => {
                Trace.WriteLine("Checking " + AutomationElementHelper.ToString(child) + "...", "UIAutomation-SearchEngine-TreeWalker");
                return(ConditionHelper.IsMeetsRequirements(conditions, child) ? child : null);
            });

            // Execute based on scope.
            switch (scope)
            {
            case TreeScope.Children:
                return((AutomationElement)ExecuteGetResult(() => ExecuteWithChildren(root, returnMatchedChild), timeout));

            case TreeScope.Descendants:
                return((AutomationElement)ExecuteGetResult(() => ExecuteWithDescendants(root, returnMatchedChild), timeout));

            default:
                throw new NotSupportedException("Scope '" + scope + "' is not supported for TreeWalker search engines");
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets a string that represents this query's condition and scope.
        /// </summary>
        /// <returns>The string representation of this query.</returns>
        public override string ToString()
        {
            var conditionsString = ConditionHelper.ToString(Conditions);
            var rootString       = AutomationElementHelper.ToString(Root);

            return(conditionsString + ", Scope=" + Scope + ", Root=" + rootString);
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets all the automation elements found using the condition specified in the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="timeout">The maximum amount of time to wait for at least one element to become available.</param>
        /// <returns>The collection of automation elements.</returns>
        public override IEnumerable GetAllResults(Query query, TimeSpan timeout)
        {
            Debug.WriteLine("AllResults - " + query, "UIAutomation-SearchEngine-TreeWalker");

            var root       = query.Root;
            var scope      = query.Scope;
            var conditions = query.Conditions;
            var results    = new ArrayList();
            // The callback for saving all matched elements.
            var saveMatchingChildren = new WithElementCallback(child => {
                Trace.WriteLine("Checking " + AutomationElementHelper.ToString(child) + "...", "UIAutomation-SearchEngine-TreeWalker");
                if (ConditionHelper.IsMeetsRequirements(conditions, child))
                {
                    results.Add(child);
                }
                return(null);
            });

            // Execute based on scope.
            switch (scope)
            {
            case TreeScope.Children:
                ExecuteWithChildren(root, saveMatchingChildren);
                return(results);

            case TreeScope.Descendants:
                ExecuteWithDescendants(root, saveMatchingChildren);
                return(results);

            default:
                throw new NotSupportedException("Scope '" + scope + "' is not supported for TreeWalker search engines");
            }
        }