AutomationElement.FindAll(TreeScope, Condition) Metode

Definisi

Mengembalikan semua AutomationElement objek yang memenuhi kondisi yang ditentukan.

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

Parameter

scope
TreeScope

Kombinasi nilai bitwise yang menentukan cakupan pencarian.

condition
Condition

Objek yang berisi kriteria yang akan dicocokkan.

Mengembalikan

Kumpulan objek yang memenuhi kondisi yang ditentukan. Jika tidak ada kecocokan, koleksi kosong akan dikembalikan.

Contoh

Contoh berikut menunjukkan cara menggunakan FindAll untuk menemukan semua tombol yang diaktifkan di jendela.

/// <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

Keterangan

Cakupan pencarian relatif terhadap elemen tempat metode dipanggil. Elemen dikembalikan dalam urutan di mana mereka ditemui di pohon.

Saat mencari jendela tingkat atas di desktop, pastikan untuk menentukan Children dalam scope, bukan Descendants. Pencarian melalui seluruh subtree desktop dapat melakukan iterasi melalui ribuan item dan menyebabkan luapan tumpukan.

Jika aplikasi klien Anda mungkin mencoba menemukan elemen di antarmuka penggunanya sendiri, Anda harus melakukan semua panggilan Automation UI pada utas terpisah.

Berlaku untuk

Lihat juga