I'm trying to use automation to find a tree item in an instance of a WinForms FolderBrowserDialog
I show the dialog in one process and then call the following in another test process:
var dlg = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Browse For Folder"));
var treectrl = dlg.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "SHBrowseForFolder ShellNameSpace Control"));
var treeview = treectrl.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "SysTreeView32"));
var item = treeCtrl.FindFirst(TreeScope.Descendants, new AndCondition(
new PropertyCondition(AutomationElement.NameProperty, "Desktop"),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem)));
dlg
, treectrl
, and treeview
come back with valid AutomationElements
but item
ends up being null
even though, when I use the Inspect app, it shows that item with the name "Desktop" as an immediate child of the treeview.
When I tried to use a TreeWalker
to walk through the tree control children, all I see are the scrollbar and its children.
Is there something else I need to do to be able to find tree items in a shell tree control?