public:
System::Windows::Automation::AutomationElementCollection ^ FindAll(System::Windows::Automation::TreeScope scope, System::Windows::Automation::Condition ^ condition);
public System.Windows.Automation.AutomationElementCollection FindAll (System.Windows.Automation.TreeScope scope, System.Windows.Automation.Condition condition);
member this.FindAll : System.Windows.Automation.TreeScope * System.Windows.Automation.Condition -> System.Windows.Automation.AutomationElementCollection
Public Function FindAll (scope As TreeScope, condition As Condition) As AutomationElementCollection
/// Finds all enabled buttons in the specified window element.
/// </summary>
/// <param name="elementWindowElement">An application or dialog window.</param>
/// <returns>A collection of elements that meet the conditions.</returns>
AutomationElementCollection FindByMultipleConditions(
AutomationElement elementWindowElement)
if (elementWindowElement == null)
throw new ArgumentException();
Condition conditions = new AndCondition(
new PropertyCondition(AutomationElement.IsEnabledProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Button)
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
elementWindowElement.FindAll(TreeScope.Children, conditions);
return elementCollection;
''' <summary>
''' Finds all enabled buttons in the specified window element.
''' </summary>
''' <param name="elementWindowElement">An application or dialog window.</param>
''' <returns>A collection of elements that meet the conditions.</returns>
Function FindByMultipleConditions(ByVal elementWindowElement As AutomationElement) As AutomationElementCollection
If elementWindowElement Is Nothing Then
Throw New ArgumentException()
End If
Dim conditions As New AndCondition(New PropertyCondition(AutomationElement.IsEnabledProperty, True), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button))
' Find all children that match the specified conditions.
Dim elementCollection As AutomationElementCollection = elementWindowElement.FindAll(TreeScope.Children, conditions)
Return elementCollection
End Function 'FindByMultipleConditions
搜索的范围相对于调用该方法的元素。 元素按树中遇到的顺序返回。
在桌面上搜索顶级窗口时,请务必指定
Children
,
scope
而不是
Descendants
。 通过桌面的整个子树进行搜索可能会循环访问数千个项目,并导致堆栈溢出。
如果客户端应用程序可能尝试在其自己的用户界面中找到元素,则必须在单独的线程上发出所有UI 自动化调用。