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))