AndCondition Constructor
Collapse the table of content
Expand the table of content

AndCondition Constructor (Condition[])


Creates a PropertyCondition that is true if all the subconditions are true.

Namespace:   System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public AndCondition(
	params Condition[] conditions


Type: System.Windows.Automation.Condition[]

Two or more subconditions.

The following example shows how to use AndCondition to find UI Automation elements that match a complex condition.

/// <summary>
/// Uses AndCondition to retrieve elements that match both of two conditions.
/// </summary>
/// <param name="elementMainWindow">An application window element.</param>
public void AndConditionExample(AutomationElement elementMainWindow)
    if (elementMainWindow == null)
        throw new ArgumentException();

    AndCondition conditionEnabledButtons = new AndCondition(
        new PropertyCondition(AutomationElement.IsEnabledProperty, true),
        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
    AutomationElementCollection enabledButtons = elementMainWindow.FindAll(
        TreeScope.Subtree, conditionEnabledButtons);
    Console.WriteLine("\nEnabled buttons:");
    foreach (AutomationElement autoElement in enabledButtons)

    // Example of getting the conditions from the AndCondition.
    Condition[] conditions = conditionEnabledButtons.GetConditions();
    Console.WriteLine("AndCondition has " + conditions.GetLength(0) + " subconditions.");


.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft