Skip to content

Condition Factory

flaui.core.condition_factory.ConditionFactory

Bases: BaseModel

ConditionFactory wraps a ConditionFactory object from FlaUI.Core.Conditions module. This class provides methods to create PropertyConditions based on automation id, control type, class name, name, and text.

by_automation_id(automation_id, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by an automation id.

Parameters:

Name Type Description Default
automation_id str

Automation ID

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_automation_id(
    self,
    automation_id: str,
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by an automation id.

    :param automation_id: Automation ID
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByAutomationId(automation_id, condition_flags_property_condition_flags.value)
    )

by_class_name(class_name, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a class name.

Parameters:

Name Type Description Default
class_name Union[str, KnownClassNames]

Class Name

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_class_name(
    self,
    class_name: Union[str, KnownClassNames],
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by a class name.

    :param class_name: Class Name
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByClassName(
            class_name if isinstance(class_name, str) else class_name.value,
            condition_flags_property_condition_flags.value,
        )
    )

by_control_type(control_type)

Creates a condition to search by a ControlType.

Parameters:

Name Type Description Default
control_type ControlType

Types of controls in Microsoft UI Automation.

required

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_control_type(self, control_type: ControlType) -> PropertyCondition:
    """Creates a condition to search by a ControlType.

    :param control_type: Types of controls in Microsoft UI Automation.
    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.ByControlType(control_type.value))

by_framework_id(framework_id, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a Framework Id.

Parameters:

Name Type Description Default
framework_id str

Framework ID

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_framework_id(
    self,
    framework_id: str,
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by a Framework Id.

    :param framework_id: Framework ID
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByFrameworkId(framework_id, condition_flags_property_condition_flags.value)
    )

by_framework_type(framework_type)

Creates a condition to search by a Framework Type.

Parameters:

Name Type Description Default
framework_type FrameworkType

Framework Type

required

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_framework_type(self, framework_type: FrameworkType) -> PropertyCondition:
    """Creates a condition to search by a Framework Type.

    :param framework_type: Framework Type
    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.ByFrameworkType(framework_type.value))

by_help_text(help_text, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a help text.

Parameters:

Name Type Description Default
help_text str

Help text

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_help_text(
    self,
    help_text: str,
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by a help text.

    :param help_text: Help text
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByHelpText(help_text, condition_flags_property_condition_flags.value)
    )

by_localized_control_type(localized_control_type, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a localized control type.

Parameters:

Name Type Description Default
localized_control_type str

Localized Control Type

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_localized_control_type(
    self,
    localized_control_type: str,
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by a localized control type.

    :param localized_control_type: Localized Control Type
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByLocalizedControlType(
            localized_control_type, condition_flags_property_condition_flags.value
        )
    )

by_name(name, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a name.

Parameters:

Name Type Description Default
name str

Name

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_name(
    self, name: str, condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_
) -> PropertyCondition:
    """Creates a condition to search by a name.

    :param name: Name
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.ByName(name, condition_flags_property_condition_flags.value))

by_process_id(process_id)

Creates a condition to search by a process id.

Parameters:

Name Type Description Default
process_id int

Process ID

required

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_process_id(self, process_id: int) -> PropertyCondition:
    """Creates a condition to search by a process id.

    :param process_id: Process ID
    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.ByProcessId(process_id))

by_text(text, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a text.

Parameters:

Name Type Description Default
text str

Text value

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_text(
    self, text: str, condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_
) -> PropertyCondition:
    """Creates a condition to search by a text.

    :param text: Text value
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.ByText(text, condition_flags_property_condition_flags.value))

by_value(value, condition_flags_property_condition_flags=PropertyConditionFlags.None_)

Creates a condition to search by a value.

Parameters:

Name Type Description Default
value str

Value

required
condition_flags_property_condition_flags PropertyConditionFlags

Contains values used in creating property conditions, defaults to PropertyConditionFlags.none

None_

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def by_value(
    self,
    value: str,
    condition_flags_property_condition_flags: PropertyConditionFlags = PropertyConditionFlags.None_,
) -> PropertyCondition:
    """Creates a condition to search by a value.

    :param value: Value
    :param condition_flags_property_condition_flags: Contains values used in creating property conditions, defaults to PropertyConditionFlags.none
    :return: Property Condition
    """
    return PropertyCondition(
        cs_condition=self.raw_cf.ByValue(value, condition_flags_property_condition_flags.value)
    )

false_condition() staticmethod

Return a condition that matches no element (C# FalseCondition.Default).

Useful as the neutral start when building a condition up with |.

Returns:

Type Description
FalseCondition

A :class:FalseCondition.

Source code in flaui/core/condition_factory.py
@staticmethod
def false_condition() -> FalseCondition:
    """Return a condition that matches no element (C# ``FalseCondition.Default``).

    Useful as the neutral start when building a condition up with ``|``.

    :return: A :class:`FalseCondition`.
    """
    return FalseCondition.default()

grid()

Searches for a DataGrid/List.

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def grid(self) -> PropertyCondition:
    """Searches for a DataGrid/List.

    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.Grid())

horizontal_scroll_bar()

Searches for a horizontal scrollbar.

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def horizontal_scroll_bar(self) -> PropertyCondition:
    """Searches for a horizontal scrollbar.

    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.HorizontalScrollBar())

menu()

Searches for a Menu/MenuBar.

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def menu(self) -> PropertyCondition:
    """Searches for a Menu/MenuBar.

    :return: Property Condition
    """
    return self.by_control_type(ControlType.Menu) | self.by_control_type(ControlType.MenuBar)

true_condition() staticmethod

Return a condition that matches every element (C# TrueCondition.Default).

Useful as the neutral start when building a condition up with &.

Returns:

Type Description
TrueCondition

A :class:TrueCondition.

Source code in flaui/core/condition_factory.py
@staticmethod
def true_condition() -> TrueCondition:
    """Return a condition that matches every element (C# ``TrueCondition.Default``).

    Useful as the neutral start when building a condition up with ``&``.

    :return: A :class:`TrueCondition`.
    """
    return TrueCondition.default()

vertical_scroll_bar()

Searches for a vertical scrollbar.

Returns:

Type Description
PropertyCondition

Property Condition

Source code in flaui/core/condition_factory.py
def vertical_scroll_bar(self) -> PropertyCondition:
    """Searches for a vertical scrollbar.

    :return: Property Condition
    """
    return PropertyCondition(cs_condition=self.raw_cf.VerticalScrollBar())

Conditions

Every condition supports &, | and ~ (or and_(), or_(), not_()). See Combining conditions.

flaui.core.condition_factory.ConditionBase

Bases: BaseModel

Base for every search condition; mirrors FlaUI.Core.Conditions.ConditionBase.

Combine conditions with the methods or the operators::

ok_button = cf.by_name("OK") & cf.by_control_type(ControlType.Button)
either = cf.by_automation_id("a") | cf.by_automation_id("b")
not_ok = ~cf.by_name("OK")

And(new_condition)

Combine with "and"; alias of :meth:and_ kept for backward compatibility.

Parameters:

Name Type Description Default
new_condition ConditionLike

Condition to combine with; a wrapper or a raw C# condition.

required

Returns:

Type Description
AndCondition

An :class:AndCondition.

Source code in flaui/core/condition_factory.py
def And(self, new_condition: ConditionLike) -> AndCondition:
    """Combine with "and"; alias of :meth:`and_` kept for backward compatibility.

    :param new_condition: Condition to combine with; a wrapper or a raw C# condition.
    :return: An :class:`AndCondition`.
    """
    return self.and_(new_condition)

Equals(value)

Compare this condition to another (C# Equals).

C# compares property conditions by property, value and flags, but compares And/Or/ Not conditions by reference. To compare two combined conditions by content, compare str(a) == str(b).

Parameters:

Name Type Description Default
value ConditionLike

Condition to compare; a wrapper or a raw C# condition.

required

Returns:

Type Description
bool

True when both conditions are equal.

Source code in flaui/core/condition_factory.py
@handle_csharp_exceptions
def Equals(self, value: ConditionLike) -> bool:
    """Compare this condition to another (C# ``Equals``).

    C# compares property conditions by property, value and flags, but compares ``And``/``Or``/
    ``Not`` conditions by reference. To compare two combined conditions by content, compare
    ``str(a) == str(b)``.

    :param value: Condition to compare; a wrapper or a raw C# condition.
    :return: True when both conditions are equal.
    """
    other = value.cs_condition if isinstance(value, ConditionBase) else value
    return bool(self.cs_condition.Equals(other))

Not(new_condition=None)

Negate; kept for backward compatibility, prefer :meth:not_ or ~.

Without an argument this matches C# ConditionBase.Not() and negates this condition. With an argument it keeps the historical Python meaning, self AND NOT new_condition, which is self & ~new_condition.

Parameters:

Name Type Description Default
new_condition Optional[ConditionLike]

Optional condition to negate and combine with this one.

None

Returns:

Type Description
Union[NotCondition, AndCondition]

A :class:NotCondition (no argument) or an :class:AndCondition.

Source code in flaui/core/condition_factory.py
def Not(self, new_condition: Optional[ConditionLike] = None) -> Union[NotCondition, AndCondition]:
    """Negate; kept for backward compatibility, prefer :meth:`not_` or ``~``.

    Without an argument this matches C# ``ConditionBase.Not()`` and negates this condition.
    With an argument it keeps the historical Python meaning, ``self AND NOT new_condition``,
    which is ``self & ~new_condition``.

    :param new_condition: Optional condition to negate and combine with this one.
    :return: A :class:`NotCondition` (no argument) or an :class:`AndCondition`.
    """
    if new_condition is None:
        return self.not_()
    return self.and_(wrap_condition(_to_cs(new_condition)).not_())

Or(new_condition)

Combine with "or"; alias of :meth:or_ kept for backward compatibility.

Parameters:

Name Type Description Default
new_condition ConditionLike

Condition to combine with; a wrapper or a raw C# condition.

required

Returns:

Type Description
OrCondition

An :class:OrCondition.

Source code in flaui/core/condition_factory.py
def Or(self, new_condition: ConditionLike) -> OrCondition:
    """Combine with "or"; alias of :meth:`or_` kept for backward compatibility.

    :param new_condition: Condition to combine with; a wrapper or a raw C# condition.
    :return: An :class:`OrCondition`.
    """
    return self.or_(new_condition)

ToString()

Render the condition as text (C# ToString).

Returns:

Type Description
str

Text form of the condition, e.g. (Name [#30005]: OK AND ControlType [#30003]: Button).

Source code in flaui/core/condition_factory.py
@handle_csharp_exceptions
def ToString(self) -> str:
    """Render the condition as text (C# ``ToString``).

    :return: Text form of the condition, e.g. ``(Name [#30005]: OK AND ControlType [#30003]: Button)``.
    """
    return str(self.cs_condition.ToString())

__and__(other)

Return self & other; see :meth:and_.

Source code in flaui/core/condition_factory.py
def __and__(self, other: ConditionLike) -> AndCondition:
    """Return ``self & other``; see :meth:`and_`."""
    return self.and_(other)

__invert__()

Return ~self; see :meth:not_.

Source code in flaui/core/condition_factory.py
def __invert__(self) -> NotCondition:
    """Return ``~self``; see :meth:`not_`."""
    return self.not_()

__or__(other)

Return self | other; see :meth:or_.

Source code in flaui/core/condition_factory.py
def __or__(self, other: ConditionLike) -> OrCondition:
    """Return ``self | other``; see :meth:`or_`."""
    return self.or_(other)

__rand__(other)

Return other & self when other is a raw C# condition.

Source code in flaui/core/condition_factory.py
def __rand__(self, other: ConditionLike) -> AndCondition:
    """Return ``other & self`` when ``other`` is a raw C# condition."""
    return wrap_condition(_to_cs(other)).and_(self)

__ror__(other)

Return other | self when other is a raw C# condition.

Source code in flaui/core/condition_factory.py
def __ror__(self, other: ConditionLike) -> OrCondition:
    """Return ``other | self`` when ``other`` is a raw C# condition."""
    return wrap_condition(_to_cs(other)).or_(self)

__str__()

Return the C# text form of the condition; see :meth:ToString.

Source code in flaui/core/condition_factory.py
def __str__(self) -> str:
    """Return the C# text form of the condition; see :meth:`ToString`."""
    return self.ToString()

and_(new_condition)

Combine this condition with another using "and" (C# ConditionBase.And).

Parameters:

Name Type Description Default
new_condition ConditionLike

Condition to combine with; a wrapper or a raw C# condition.

required

Returns:

Type Description
AndCondition

An :class:AndCondition that matches when both conditions match.

Source code in flaui/core/condition_factory.py
@handle_csharp_exceptions
def and_(self, new_condition: ConditionLike) -> AndCondition:
    """Combine this condition with another using "and" (C# ``ConditionBase.And``).

    :param new_condition: Condition to combine with; a wrapper or a raw C# condition.
    :return: An :class:`AndCondition` that matches when both conditions match.
    """
    return AndCondition(cs_condition=self.cs_condition.And(_to_cs(new_condition)))

not_()

Negate this condition (C# ConditionBase.Not).

Returns:

Type Description
NotCondition

A :class:NotCondition that matches when this condition does not.

Source code in flaui/core/condition_factory.py
@handle_csharp_exceptions
def not_(self) -> NotCondition:
    """Negate this condition (C# ``ConditionBase.Not``).

    :return: A :class:`NotCondition` that matches when this condition does not.
    """
    return NotCondition(cs_condition=self.cs_condition.Not())

or_(new_condition)

Combine this condition with another using "or" (C# ConditionBase.Or).

Parameters:

Name Type Description Default
new_condition ConditionLike

Condition to combine with; a wrapper or a raw C# condition.

required

Returns:

Type Description
OrCondition

An :class:OrCondition that matches when either condition matches.

Source code in flaui/core/condition_factory.py
@handle_csharp_exceptions
def or_(self, new_condition: ConditionLike) -> OrCondition:
    """Combine this condition with another using "or" (C# ``ConditionBase.Or``).

    :param new_condition: Condition to combine with; a wrapper or a raw C# condition.
    :return: An :class:`OrCondition` that matches when either condition matches.
    """
    return OrCondition(cs_condition=self.cs_condition.Or(_to_cs(new_condition)))

flaui.core.condition_factory.PropertyCondition

Bases: ConditionBase

A condition that checks one property; mirrors FlaUI.Core.Conditions.PropertyCondition.

For backward compatibility every other condition wrapper derives from this class, so APIs typed as taking a PropertyCondition accept any condition. Property, Value and PropertyConditionFlags are only meaningful on a real property condition.

Property property

The property that should be checked.

Returns:

Type Description
Any

Property

PropertyConditionFlags property

Optional flags that are used when checking the property.

Returns:

Type Description
'PropertyConditionFlags'

Property Condition Flags

Value property

The value that is used for checking.

Returns:

Type Description
Union[str, Any]

Value

flaui.core.condition_factory.AndCondition

Bases: JunctionConditionBase

A condition that matches when all its conditions match; mirrors AndCondition.

flaui.core.condition_factory.OrCondition

Bases: JunctionConditionBase

A condition that matches when any of its conditions match; mirrors OrCondition.

flaui.core.condition_factory.JunctionConditionBase

Bases: PropertyCondition

Base for conditions that join several conditions; mirrors JunctionConditionBase.

child_count property

Return how many conditions this junction joins.

Returns:

Type Description
int

Number of joined conditions.

conditions property

Return the joined conditions.

Returns:

Type Description
List[PropertyCondition]

The conditions, each wrapped in its matching Python class.

flaui.core.condition_factory.NotCondition

Bases: PropertyCondition

A condition that negates another; mirrors FlaUI.Core.Conditions.NotCondition.

condition property

Return the negated condition.

Returns:

Type Description
PropertyCondition

The inner condition, wrapped in its matching Python class.

flaui.core.condition_factory.BoolCondition

Bases: PropertyCondition

A condition that is always true or always false; mirrors FlaUI.Core.Conditions.BoolCondition.

boolean_value property

Return the fixed result of this condition.

Returns:

Type Description
bool

True for a :class:TrueCondition, False for a :class:FalseCondition.

flaui.core.condition_factory.TrueCondition

Bases: BoolCondition

A condition that matches every element; mirrors FlaUI.Core.Conditions.TrueCondition.

default() classmethod

Return the shared true condition (C# TrueCondition.Default).

Returns:

Type Description
TrueCondition

A :class:TrueCondition.

Source code in flaui/core/condition_factory.py
@classmethod
@handle_csharp_exceptions
def default(cls) -> TrueCondition:
    """Return the shared true condition (C# ``TrueCondition.Default``).

    :return: A :class:`TrueCondition`.
    """
    return cls(cs_condition=CSTrueCondition.Default)

flaui.core.condition_factory.FalseCondition

Bases: BoolCondition

A condition that matches no element; mirrors FlaUI.Core.Conditions.FalseCondition.

default() classmethod

Return the shared false condition (C# FalseCondition.Default).

Returns:

Type Description
FalseCondition

A :class:FalseCondition.

Source code in flaui/core/condition_factory.py
@classmethod
@handle_csharp_exceptions
def default(cls) -> FalseCondition:
    """Return the shared false condition (C# ``FalseCondition.Default``).

    :return: A :class:`FalseCondition`.
    """
    return cls(cs_condition=CSFalseCondition.Default)

flaui.core.condition_factory.wrap_condition(cs_condition)

Wrap a raw C# condition in the matching Python class.

Parameters:

Name Type Description Default
cs_condition Any

A C# FlaUI.Core.Conditions.ConditionBase instance.

required

Returns:

Type Description
PropertyCondition

A :class:TrueCondition, :class:FalseCondition, :class:AndCondition, :class:OrCondition, :class:NotCondition or :class:PropertyCondition.

Source code in flaui/core/condition_factory.py
def wrap_condition(cs_condition: Any) -> PropertyCondition:
    """Wrap a raw C# condition in the matching Python class.

    :param cs_condition: A C# ``FlaUI.Core.Conditions.ConditionBase`` instance.
    :return: A :class:`TrueCondition`, :class:`FalseCondition`, :class:`AndCondition`,
        :class:`OrCondition`, :class:`NotCondition` or :class:`PropertyCondition`.
    """
    if isinstance(cs_condition, CSTrueCondition):
        return TrueCondition(cs_condition=cs_condition)
    if isinstance(cs_condition, CSFalseCondition):
        return FalseCondition(cs_condition=cs_condition)
    if isinstance(cs_condition, CSAndCondition):
        return AndCondition(cs_condition=cs_condition)
    if isinstance(cs_condition, CSOrCondition):
        return OrCondition(cs_condition=cs_condition)
    if isinstance(cs_condition, CSNotCondition):
        return NotCondition(cs_condition=cs_condition)
    return PropertyCondition(cs_condition=cs_condition)