gpt4 book ai didi

c# - 在Windows Automation中使用部分NameProperty查找Windows控件

转载 作者:行者123 更新时间:2023-12-03 11:13:31 24 4
gpt4 key购买 nike

我正在尝试使用部分NameProperty识别Windows静态文本控件。这是我的代码:

// Get a reference to the window
AutomationElement epoWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MsiDialog"));
// Get a reference to the control
AutomationElement epoControl = epoWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, controlText));

目前,我需要完整的controlText字符串才能正常工作,但我想搜索该字符串的一部分并返回找到的所有控件。
我该怎么做呢?
谢谢,
约翰

最佳答案

您可以使用预定义的TrueCondition对子集合进行迭代,如下所示:

  foreach(AutomationElement child in epoWindow.FindAll(TreeScope.Subtree, Condition.TrueCondition))
{
if (child.Current.Name.Contains("whatever"))
{
// do something
}
}

PS:如果您不想降低应用程序的性能(如果它具有较大的子层次结构)或无限期等待,则需要仔细选择 TreeScope

关于c# - 在Windows Automation中使用部分NameProperty查找Windows控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30804184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com