简体   繁体   English

如何判断元素是否与Microsoft UI Automation中的PropertyCondition匹配?

[英]How can I tell if an element matches a PropertyCondition in Microsoft UI Automation?

I'm trying to find an AutomationElement in a particular row of a GridView (so there are many identical elements). 我正在尝试在GridView的特定行中找到一个AutomationElement(因此有许多相同的元素)。 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. 我从简单的PropertyConditions开始。

Here's my test: 这是我的测试:

[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));
    }
}

And here's the code: 这是代码:

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

Unfortunately the test fails. 不幸的是测试失败了。 The ControlType of the root element (the desktop) is indeed ControlType.Pane, but bizarrely the PropertyCondition.Value is "50033". 根元素(桌面)的ControlType确实是ControlType.Pane,但奇怪的是PropertyCondition.Value是“50033”。

Any ideas as to how I can test a PropertyCondition outside of FindFirst / FindAll? 关于如何在FindFirst / FindAll之外测试PropertyCondition的任何想法?

(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.) (我的解决方法是创建我自己的条件类型并测试相反,但我想检查我是不是误解了某些东西/做了一些愚蠢的事情。)

Found it. 找到了。

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! 希望这会帮助别人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Microsoft UI Automation从Point获取文本值? - How to get the text value from Point using Microsoft UI Automation? 使用XMLTextReader,如何知道我在哪个元素上? - Using XMLTextReader, how can I tell which element I am on? 如何将UI自动化元素移动到其他位置? - How to move an UI automation element to a different location? Microsoft Dynamic AX的UI自动化 - UI Automation of Microsoft Dynamic AX 如何判断 blazor 中是否存在元素引用 - How can I tell if an element reference does exist in blazor 如何判断Microsoft.WindowsAzure.Storage.DataMovement.TransferManager的CopyDirectoryAsync完成了? - How can I tell when CopyDirectoryAsync from Microsoft.WindowsAzure.Storage.DataMovement.TransferManager has finished? 如何使用 WPF 的 UI 自动化向 AutomationElement 发送右键单击事件? - How can I send a right-click event to an AutomationElement using WPF's UI automation? 如何使用Windows应用程序驱动程序在UI自动化单元测试期间验证WPF复选框的状态? - How can I verify the state of a WPF checkbox during a UI Automation Unit Test using the Windows Application Driver? Microsoft Automation UI鼠标单击给定位置 - Microsoft Automation UI mouse click on a given position 使用Microsoft的Visual UI Automation验证 - Using Microsoft's Visual UI Automation Verify
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM