AutomationElement.FindAll(TreeScope, Condition) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳所有 AutomationElement 符合指定條件的物件。
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
參數
- scope
- TreeScope
一個位元組合的值,用來指定搜尋範圍。
- condition
- Condition
包含匹配條件的物件。
傳回
一組滿足指定條件的物件。 若無匹配,則會回傳一個空集合。
範例
以下範例展示了如何使用 FindAll 視窗中所有啟用的按鈕。
/// <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>
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
備註
搜尋範圍相對於方法被呼叫的元素而定。 元素依照在樹中遇到的順序回傳。
在桌面搜尋頂層視窗時,務必在 中指定 Childrenscope,而非 Descendants。 搜尋桌面整個子樹可能會遍歷數千個項目,導致堆疊溢位。
如果你的客戶端應用程式可能會在自己的使用者介面中尋找元素,你必須在獨立的執行緒中呼叫所有 使用者介面自動化。