Example #1
0
        /// <summary>
        /// Check whether UIElement is same or not.
        /// </summary>
        /// <param name="element1"></param>
        /// <param name="element2"></param>
        /// <returns></returns>
        public static bool IsSameUIElement(this A11yElement element1, A11yElement element2)
        {
            if (element1 != null && element2 != null)
            {
                return(element1.IsSameUIElement(element2.RuntimeId, element2.BoundingRectangle, element2.ControlTypeId, element2.Name));
            }

            return(false);
        }
Example #2
0
 /// <summary>
 /// Select the specified element if it meets all eligibilty requirements
 /// </summary>
 /// <param name="element">The potential element to select</param>
 /// <returns>true if the element was selected</returns>
 protected bool SelectElementIfItIsEligible(A11yElement element)
 {
     if (element != null && !element.IsRootElement() &&
         !element.IsSameUIElement(SelectedElementRuntimeId, SelectedBoundingRectangle, SelectedControlTypeId, SelectedName))
     {
         SelectedElementRuntimeId  = element.RuntimeId;
         SelectedBoundingRectangle = element.BoundingRectangle;
         SelectedControlTypeId     = element.ControlTypeId;
         SelectedName = element.Name;
         SetElement?.Invoke(element);
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// Set Parent to build ancestry tree
        /// </summary>
        /// <param name="e"></param>
        /// <param name="uniqueId"></param>
        private void SetParent(A11yElement e, int uniqueId)
        {
            if (e == null || e.PlatformObject == null || e.IsRootElement())
            {
                return;
            }

            try
            {
                var puia = this.TreeWalker.GetParentElement((IUIAutomationElement)e.PlatformObject);
                if (puia == null)
                {
                    return;
                }

#pragma warning disable CA2000 // Call IDisposable.Dispose()
                var parent = new DesktopElement(puia, true, SetMembers);
                parent.PopulateMinimumPropertiesForSelection();

                // we need to avoid infinite loop of self reference as parent.
                // it is a probably a bug in UIA or the target app.
                if (e.IsSameUIElement(parent) == false)
                {
                    parent.IsAncestorOfSelected = true;
                    parent.Children.Add(e);
                    e.Parent = parent;
                    this.Items.Add(parent);
                    parent.UniqueId = uniqueId;

                    SetParent(parent, uniqueId - 1);
                }
#pragma warning restore CA2000
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                ex.ReportException();
                // ignore to show the best efforts.
                System.Diagnostics.Trace.WriteLine(ex);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }