有没有一种方法可以使用AutomationElement.FindFirst在System.Windows.Forms.FolderBrowserDialog中找到项目?

时间:2020-10-15 19:53:18

标签: c# .net winforms automation

我正在尝试使用自动化在WinForms const creds = { username: "user", password: "pass" } function Keys(key) { console.log(key); return creds[key]; } const usernameValue = Keys("username"); 的实例中查找树项 我在一个过程中显示对话框,然后在另一个测试过程中调用以下对话框:

FolderBrowserDialog

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))); dlgtreectrl返回有效的treeview,但是AutomationElements最终还是item,即使我使用Inspect应用程序,它将显示名称为“ Desktop”的项目作为树视图的直接子项。

当我尝试使用null浏览树控件的子级时,我看到的只是滚动条及其子级。

要在shell树控件中找到树项,还需要做其他事情吗?

0 个答案:

没有答案