Here is my code:
public static string DumpUIATree(this AutomationElement element, bool dumpFullInfo = false)
{
var s = element.Name() + " : " + element.ControlType().ProgrammaticName;
DumpChildrenRecursively(element, 1, ref s, dumpFullInfo);
return s;
}
private static List<AutomationElement> GetChildNodes(this AutomationElement automationElement)
{
var children = new List<AutomationElement>();
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement child = walker.GetFirstChild(automationElement);
while (child != null)
{
children.Add(child);
child = walker.GetNextSibling(child);
}
return children;
}
private static void DumpChildrenRecursively(AutomationElement node, int level, ref string s, bool dumpFullInfo = false)
{
var children = node.GetChildNodes();
foreach (var child in children)
{
if (child != null)
{
for (int i = 0; i < level; i++)
s += "-";
s += " " + child.Name() + " : " + child.ControlType().ProgrammaticName + "\r\n";
if (dumpFullInfo)
{
foreach (var prop in child.GetSupportedProperties())
{
s += " > " + prop.ProgrammaticName + " = " + child.GetCurrentPropertyValue(prop) + "\r\n";
}
s += "\r\n";
}
DumpChildrenRecursively(child, level + 1, ref s, dumpFullInfo);
}
}
}