C# Windows UIAutomation未检测到窗口元素
我试图使用UIAutomation访问文件夹,但窗口元素未检测到 当我使用UI Spy检查时,它显示了具有类名和进程ID的元素。我正在查看的元素是window元素,它位于explorer进程下。所以当我尝试使用下面的代码时,它返回0个元素。我附上的参考图像。请帮帮我C# Windows UIAutomation未检测到窗口元素,c#,ui-automation,C#,Ui Automation,我试图使用UIAutomation访问文件夹,但窗口元素未检测到 当我使用UI Spy检查时,它显示了具有类名和进程ID的元素。我正在查看的元素是window元素,它位于explorer进程下。所以当我尝试使用下面的代码时,它返回0个元素。我附上的参考图像。请帮帮我 正如@Damien_的异教徒建议我使用根元素属性。在RootElement属性的帮助下,找到了解决方案。在当前桌面上查找元素非常有用 下面是我自己找到的解决方案 AutomationElementCollection deskto
正如@Damien_的异教徒建议我使用根元素属性。在RootElement属性的帮助下,找到了解决方案。在当前桌面上查找元素非常有用 下面是我自己找到的解决方案
AutomationElementCollection desktopChildren = AutomationElement.RootElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Windows));
foreach(AutomationElement dChil in desktopChildren)
{
if (dChil.Current.Name.Contains("Chipset Software"))
{
Console.WriteLine($"{MethodBase.GetCurrentMethod()}: Found Chipset_Software Window");
}
}
非常感谢@Damien_不信者。当自动化暴露属性“获取当前桌面的根AutomationElement”时,为什么还要摆弄进程、主窗口等?@Damien_不信者非常感谢。使用了根元素属性,它帮助我找到了窗口元素。
AutomationElementCollection desktopChildren = AutomationElement.RootElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Windows));
foreach(AutomationElement dChil in desktopChildren)
{
if (dChil.Current.Name.Contains("Chipset Software"))
{
Console.WriteLine($"{MethodBase.GetCurrentMethod()}: Found Chipset_Software Window");
}
}