Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows UIAutomation未检测到窗口元素_C#_Ui Automation - Fatal编程技术网

C# Windows UIAutomation未检测到窗口元素

C# Windows UIAutomation未检测到窗口元素,c#,ui-automation,C#,Ui Automation,我试图使用UIAutomation访问文件夹,但窗口元素未检测到 当我使用UI Spy检查时,它显示了具有类名和进程ID的元素。我正在查看的元素是window元素,它位于explorer进程下。所以当我尝试使用下面的代码时,它返回0个元素。我附上的参考图像。请帮帮我 正如@Damien_的异教徒建议我使用根元素属性。在RootElement属性的帮助下,找到了解决方案。在当前桌面上查找元素非常有用 下面是我自己找到的解决方案 AutomationElementCollection deskto

我试图使用UIAutomation访问文件夹,但窗口元素未检测到

当我使用UI Spy检查时,它显示了具有类名和进程ID的元素。我正在查看的元素是window元素,它位于explorer进程下。所以当我尝试使用下面的代码时,它返回0个元素。我附上的参考图像。请帮帮我


正如@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");
            }
       }