What can cause (managed) UIAutomation to get its own link when listing children

We found a dialogue where a certain group of controls seems to refer to itself recursively. Please note that the application provides the MSAA / LegacyAccessible interface for the user interface automation infrastructure, such applications seem more fragile and seem to cause all sorts of grief, may or may not be relevant for this problem.

So, as an example, in search of a window using FindFirst, if the element is before this self-reference element, everything is fine, if after that it continues, it forever collects memory both on the client and on the server.

Condition condition = new PropertyCondition(AutomationElement.IsPasswordProperty, true);
AutomationElement myPassword = element.FindFirst(TreeScope.Descendants, condition);

Working with direct children has the same problem.

private void WalkControlElements(AutomationElement rootElement, ...)
{
    AutomationElementCollection childElements = rootElement.FindAll(TreeScope.Children, Automation.ControlViewCondition);

    foreach (AutomationElement elementNode in childElements)
    {
        WalkControlElements(elementNode, ... );
    }
}

TreeWalker. ControlIViewWalker

private void WalkControlElements(AutomationElement rootElement, ...)
{
    AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(rootElement);

    while (elementNode != null)
    {
        WalkControlElements(elementNode, ... );
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
    }
}

  group ""
     button "Home"

  group ""
     button "Home"
     group ""
        button "Home"
        group ""
           button "Home"
           group ""
              button "Home"
              group ""
                 ...

, , , , . Inpsect MSAA UIAutomation .

, , , , Inspect , . SO, Inspect , .

, ?

. , , .

ref List<AutomationElement> controls
  if (controls.Contains(autoElement)) 
+3
2

, ( node , TreeWalker ). ( ):

  • GetUpdatedCache CacheRequest:: Current: , . .
  • GetHashCode /: - , /.

, , UI Automation () ( ), , ( win32, winform, wpf..), .

, 2 :

  • .
  • , API , node.
+3

.

group ""
   button "Home"  <-- want this item, but item has invalid parent!
   group ""       <-- don't want item, item has invalid parent, and all children do also
      button "Home"
      group ""

private void WalkControlElements(AutomationElement rootElement, ...)
{
    AutomationElementCollection childElements = rootElement.FindAll(TreeScope.Children, Automation.ControlViewCondition);

    foreach (AutomationElement elementNode in childElements)
    {
        if( rootElement == TreeWalker.ControlViewWalker.GetParent(elementNode) )
            WalkControlElements(elementNode, ... );
    }
}

group ""

: | "home"

, .

private void WalkControlElements(AutomationElement rootElement, ...){
     WalkControlElements(elementNode, false, ... );
}

private void WalkControlElements(AutomationElement rootElement, bool treeValidationExceptionShouldFail, ...)
{
    AutomationElementCollection childElements = rootElement.FindAll(TreeScope.Children, Automation.ControlViewCondition);

    foreach (AutomationElement elementNode in childElements)
    {
        if( rootElement == TreeWalker.ControlViewWalker.GetParent(elementNode) )
            WalkControlElements(elementNode, treeValidationExceptionShouldFail, ... );
        else
            WalkControlElements(elementNode, true, ... );
    }
}

group ""
   button "Home" 
   group ""       <-- don't want, but at least we stopped recursion
0

All Articles