【问题标题】:How can I tell if an element matches a PropertyCondition in Microsoft UI Automation?如何判断元素是否与 Microsoft UI 自动化中的 PropertyCondition 匹配?
【发布时间】:2010-07-26 00:32:05
【问题描述】:

我试图在 GridView 的特定行中找到一个 AutomationElement(因此有许多相同的元素)。我正在迭代行中的元素,我想使用匹配器来查看特定元素是否与我传递给它的条件匹配。我从简单的 PropertyConditions 开始。

这是我的测试:

[TestFixture]
public class ConditionMatcherBehaviour
{
    [Test]
    public void ShouldMatchAPropertyConditionByItsValue()
    {
        var conditionMatcher = new ConditionMatcher();
        var condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane);
        Assert.True(conditionMatcher.Matches(AutomationElement.RootElement, condition));
    }
}

这是代码:

public class ConditionMatcher : IMatchConditions
{
    public bool Matches(AutomationElement element, Condition condition)
    {
        var propertyCondition = (PropertyCondition) condition;
        return propertyCondition.Value.Equals(element.GetCurrentPropertyValue(propertyCondition.Property));
    }
}

不幸的是,测试失败了。根元素(桌面)的ControlType确实是ControlType.Pane,但奇怪的是PropertyCondition.Value是“50033”。

关于如何在 FindFirst / FindAll 之外测试 PropertyCondition 有什么想法吗?

(我的解决方法是创建自己的条件类型并对其进行测试,但我想检查一下我没有误解某事/做某事愚蠢。)

【问题讨论】:

    标签: c# wpf ui-automation


    【解决方案1】:

    找到了。

    public class ConditionMatcher : IMatchConditions
    {
        public bool Matches(AutomationElement element, Condition condition)
        {
            return new TreeWalker(condition).Normalize(element) != null;
        }
    }
    

    不是很明显,但它适用于匹配和不匹配的条件。感谢所有看过并思考了一段时间的人。希望这对其他人有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 2010-09-25
      • 1970-01-01
      • 2011-11-02
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多