white-framework - 使用 UIAutomation .NET 在桌面上查找所有窗口

标签 white-framework microsoft-ui-automation

我正在尝试使用 .NET UIAutomation OR White 框架查找所有桌面窗口。
我试过 :

1.)

            AutomationElement rootElement = AutomationElement.RootElement;
            var winCollection = rootElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);

2.)
            Desktop.Instance.Windows();

两者都抛出 ArgumentException。
请让我知道是否有其他方法可以做到这一点...

更新/回答:Desktop.Instance.Windows();工作正常,除了它在使用 VS2010 调试代码时抛出异常。

最佳答案

使用 TreeScope.Children如果您想访问桌面的直接子元素应该可以工作::

    AutomationElement rootElement = AutomationElement.RootElement;
    var winCollection = rootElement.FindAll(TreeScope.Children, Condition.TrueCondition);

    foreach (AutomationElement element in winCollection)
        Console.WriteLine(element.Current.Name);

关于white-framework - 使用 UIAutomation .NET 在桌面上查找所有窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191265/

相关文章:

c# - Application.GetWindow() *非常*慢

c# - 如何使用 Microsoft UI Automation 从 Point 获取文本值?

c++ - GetClickablePoint 不适用于 UI 自动化

c++ - 如何在线程之间传递 IUIAutomationElement

c# - 与 UIAutomationCore 相比,System.Windows.Automation 在枚举表行时非常慢

configuration - 如何配置 TestStack.White 超时?

c# - UI 自动化事件被引发两次

c# - 自定义控件上的 AutomationProperties.AutomationId 未公开

c# - Backgroundworker 内部的测试执行突然在具有许多子元素的元素上结束

wpf - 为什么 Inspect.exe 会频繁挂起且显示的 AutomationId 不一致?