我怎么能告诉我们,如果一个元素在Microsoft UI自动化一个PropertyCondition相匹配? [英] How can I tell if an element matches a PropertyCondition in Microsoft UI Automation?

查看:830
本文介绍了我怎么能告诉我们,如果一个元素在Microsoft UI自动化一个PropertyCondition相匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个GridView的特定行的AutomationElement(所以有很多相同的元素)。我遍历行中的元素,我想用一个匹配,看是否有特定的元素,我传递给它的条件相匹配。 。我开始用简单的PropertyConditions

I'm trying to find an AutomationElement in a particular row of a GridView (so there are many identical elements). I'm iterating over the elements in the row, and I'd like to use a matcher to see if a particular element matches the Condition I'm passing to it. I'm starting with simple 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.Value50033。

Unfortunately the test fails. The ControlType of the root element (the desktop) is indeed ControlType.Pane, but bizarrely the PropertyCondition.Value is "50033".

任何想法,我怎么能考FindFirst中/的FindAll以外的PropertyCondition?

Any ideas as to how I can test a PropertyCondition outside of FindFirst / FindAll?

(我的解决方法是创建自己的条件类型,并测试代替,但我想确认我不是误解的东西/做一些愚蠢的。)

(My workaround is to create my own condition type and test that instead, but I'd like to check that I'm not misunderstanding something / doing something stupid.)

推荐答案

找到了。

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



不完全是显而易见的,但它同时适用于匹配和非匹配条件。感谢所有谁看了一下,思考了一下。希望这会帮助别人!

Not exactly obvious, but it works for both matching and non-matching conditions. Thanks to all who looked and thought about it for a bit. Hopefully this will help someone else!

这篇关于我怎么能告诉我们,如果一个元素在Microsoft UI自动化一个PropertyCondition相匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆