AutomationElement.FindFirst(TreeScope, Condition) 메서드

정의

지정된 조건에 맞는 첫 번째 자식이나 하위 요소를 반환합니다.

public:
 System::Windows::Automation::AutomationElement ^ FindFirst(System::Windows::Automation::TreeScope scope, System::Windows::Automation::Condition ^ condition);
public System.Windows.Automation.AutomationElement FindFirst (System.Windows.Automation.TreeScope scope, System.Windows.Automation.Condition condition);
member this.FindFirst : System.Windows.Automation.TreeScope * System.Windows.Automation.Condition -> System.Windows.Automation.AutomationElement
Public Function FindFirst (scope As TreeScope, condition As Condition) As AutomationElement

매개 변수

scope
TreeScope

검색 범위를 지정하는 값의 비트 조합입니다.

condition
Condition

대조할 조건이 들어 있는 개체입니다.

반환

AutomationElement

조건에 맞는 첫 번째 요소이거나, 조건에 맞는 요소가 없으면 null입니다.

예제

다음 예제에는 해당 식별자에서 자식 창을 찾는 방법을 보여 줍니다.

/// <summary>
/// Find a UI Automation child element by ID.
/// </summary>
/// <param name="controlName">Name of the control, such as "button1"</param>
/// <param name="parentElement">Parent element, such as an application window, or the 
/// AutomationElement.RootElement when searching for the application window.</param>
/// <returns>The UI Automation element.</returns>
private AutomationElement FindChildElement(String controlName, AutomationElement rootElement)
{
    if ((controlName == "") || (rootElement == null))
    {
        throw new ArgumentException("Argument cannot be null or empty.");
    }
    // Set a property condition that will be used to find the main form of the
    // target application. In the case of a WinForms control, the name of the control
    // is also the AutomationId of the element representing the control.
    Condition propCondition = new PropertyCondition(
        AutomationElement.AutomationIdProperty, controlName, PropertyConditionFlags.IgnoreCase);

    // Find the element.
    return rootElement.FindFirst(TreeScope.Element | TreeScope.Children, propCondition);
}
''' <summary>
''' Find a UI Automation child element by ID.
''' </summary>
''' <param name="controlName">Name of the control, such as "button1"</param>
''' <param name="rootElement">Parent element, such as an application window, or the 
''' AutomationElement.RootElement when searching for the application window.</param>
''' <returns>The UI Automation element.</returns>
Private Function FindChildElement(ByVal controlName As String, ByVal rootElement As AutomationElement) _
    As AutomationElement
    If controlName = "" OrElse rootElement Is Nothing Then
        Throw New ArgumentException("Argument cannot be null or empty.")
    End If
    ' Set a property condition that will be used to find the main form of the
    ' target application. In the case of a WinForms control, the name of the control
    ' is also the AutomationId of the element representing the control.
    Dim propCondition As New PropertyCondition(AutomationElement.AutomationIdProperty, _
        controlName, PropertyConditionFlags.IgnoreCase)

    ' Find the element.
    Return rootElement.FindFirst(TreeScope.Element Or TreeScope.Children, propCondition)

End Function 'FindChildElement

설명

검색 범위가 메서드를 호출 하는 요소를 기준으로 합니다.

바탕 화면에서 최상위 창을 검색 하는 경우 지정 해야 Childrenscope아니라 Descendants합니다. 데스크톱의 전체 하위 트리를 통해 검색 수천 개의 항목을 반복을 스택 오버플로가 발생할 수 있습니다.

클라이언트 애플리케이션이 자체 사용자 인터페이스에서 요소를 찾으려고 할 수 있는 경우 별도의 스레드에서 모든 UI 자동화 호출을 수행해야 합니다.

적용 대상

추가 정보