【问题标题】:Windows UIAutomation creating PropertyConditionWindows UIAutomation 创建 PropertyCondition
【发布时间】:2014-08-12 05:15:52
【问题描述】:

我正在将一些 UI 自动化从 System.Windows.Automation API 移植到本机 UIAutomationClient API,并且遇到了一个感觉很简单的问题,但找不到解决方案。

我需要使用以下代码来查找 UI 元素:

IUIAutomationElement namedElement = currentWindow.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants, nameCondition);

这里,nameCondition 对象应该是一个 IUIAutomationCondition 来将元素的名称与字符串进行比较。

使用旧的 System.Windows.Automation 我会这样写:

PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, "name");

但是,我不知道如何使用 UIAutomation API 创建 PropertyCondition。我所见过的唯一例子似乎暗示了以下几点:

IUIAutomationCondition nameCondition = cuiAutomation.CreatePropertyCondition(propertyIdName, "name");   

这里,propertyIdName 应该是一个表示 NameProperty 的 int。但是,我无法弄清楚如何在这里获得正确的 int 。我认为它必须作为常量在 UIAutomation API 中的某个地方,但找不到它。

【问题讨论】:

    标签: c# user-interface automation


    【解决方案1】:

    我发现了以下有用的页面,其中列出了这些属性 ID 的值:http://msdn.microsoft.com/en-us/library/windows/desktop/ee684017(v=vs.85).aspx

    例如:UIA_AutomationIdPropertyId = 30011

    使用此页面,我在代码中为需要使用的属性 ID 定义了 int 常量。我不认为这可能是正确的答案,但至少它能让我取得进步。

    【讨论】:

      【解决方案2】:

      不是一个完整的答案,但我在 UIAutomationClient.UIA_PropertyIds 中找到了值。不幸的是,尝试直接从您的代码中访问它们仍然会导致错误,但您可以轻松地对它们“转到定义”以获取 id 值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-19
        • 2013-11-28
        • 2022-07-07
        • 2022-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-28
        相关资源
        最近更新 更多