Skip to content

Patterns

Python wrappers around the C# FlaUI.Core.Patterns types. The Patterns facade (exposed as element.patterns) gives typed, snake_case access to each UI Automation pattern, mirroring the C# element.Patterns.<Pattern>.Pattern shape one-to-one:

# C#:  element.Patterns.Value.Pattern.Value.Value
element.patterns.value.pattern.value.value

# C#:  element.Patterns.Toggle.IsSupported
element.patterns.toggle.is_supported

Each pattern wraps a native C# pattern object, always reachable via raw_pattern as an escape hatch for members that are not yet wrapped. Patterns are ported incrementally by family.

Pattern parity

The wrapper covers all 34 patterns that FlaUI exposes through FrameworkAutomationElementBase.IFrameworkPatterns — full parity with the FlaUI C# API. The Microsoft UIA CustomNavigation pattern is intentionally not included: FlaUI itself does not surface it (it lives only in the underlying Interop.UIAutomationClient COM layer), so wrapping it would break the 1:1-with-FlaUI mapping. It is tracked as a post-v1 wishlist item in GH-121.

flaui.core.patterns

Python wrappers for FlaUI C# UI Automation patterns.

This package mirrors FlaUI.Core.Patterns. The :class:~flaui.core.patterns.patterns.Patterns facade (exposed as element.patterns) gives typed, snake_case access to each pattern, matching the C# element.Patterns.<Pattern>.Pattern shape. Each pattern wraps a native C# pattern object reachable via :attr:~flaui.core.patterns.pattern_base.PatternBase.raw_pattern.

All UI Automation patterns from FlaUI.Core.Patterns are wrapped here.

AnnotationPattern

Bases: PatternBase

Represents the UI Automation Annotation pattern for annotation elements (comments, etc.).

annotation_type property

Return the annotation type identifier.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the AnnotationType value.

annotation_type_name property

Return the localized annotation type name.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the type name.

author property

Return the author of the annotation.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the author.

date_time property

Return the date and time the annotation was created.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the date/time string.

target property

Return the element the annotation targets.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the target element.

AutomationPattern

Bases: BaseModel, Generic[TPattern]

Provides access to a single pattern on an element, mirroring C# IAutomationPattern<T>.

is_supported property

Return whether the element supports this pattern.

Returns:

Type Description
bool

True if the pattern is supported, else False.

pattern property

Return the wrapped pattern, raising if the pattern is not supported.

Returns:

Type Description
TPattern

The wrapped pattern instance.

Raises:

Type Description
PatternNotSupportedException

If the element does not support the pattern.

pattern_or_default property

Return the wrapped pattern, or None if the pattern is not supported.

Returns:

Type Description
Optional[TPattern]

The wrapped pattern instance, or None when unsupported.

try_get_pattern()

Try to get the wrapped pattern.

Returns:

Type Description
Tuple[bool, Optional[TPattern]]

A tuple (supported, pattern_or_none).

Source code in flaui/core/patterns/automation_pattern.py
def try_get_pattern(self) -> Tuple[bool, Optional[TPattern]]:
    """Try to get the wrapped pattern.

    :return: A tuple ``(supported, pattern_or_none)``.
    """
    pattern = self.pattern_or_default
    return pattern is not None, pattern

DockPattern

Bases: PatternBase

Represents the UI Automation Dock pattern for controls docked within a docking container.

dock_position property

Return the control's current dock position.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the DockPosition value.

set_dock_position(dock_position)

Set the control's dock position.

Parameters:

Name Type Description Default
dock_position DockPosition

The desired dock position.

required
Source code in flaui/core/patterns/dock_pattern.py
@handle_csharp_exceptions
def set_dock_position(self, dock_position: DockPosition) -> None:
    """Set the control's dock position.

    :param dock_position: The desired dock position.
    """
    self.raw_pattern.SetDockPosition(dock_position.value)

DragPattern

Bases: PatternBase

Represents the UI Automation Drag pattern for elements that can be dragged.

drop_effect property

Return a localized description of the drop effect when dragging.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the drop effect.

drop_effects property

Return the full set of localized drop effect descriptions.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the drop effects.

grabbed_items property

Return the items being dragged together with this element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the grabbed items.

is_grabbed property

Return whether the element is currently grabbed for dragging.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the grabbed flag.

DropTargetPattern

Bases: PatternBase

Represents the UI Automation DropTarget pattern for elements that accept drops.

drop_target_effect property

Return a localized description of the effect when dropping onto this target.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the drop target effect.

drop_target_effects property

Return the full set of localized drop target effect descriptions.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the drop target effects.

ExpandCollapsePattern

Bases: PatternBase

Represents the UI Automation ExpandCollapse pattern for controls that expand and collapse.

expand_collapse_state property

Return the current expand/collapse state.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the ExpandCollapseState value.

collapse()

Collapse the control.

Source code in flaui/core/patterns/expand_collapse_pattern.py
@handle_csharp_exceptions
def collapse(self) -> None:
    """Collapse the control."""
    self.raw_pattern.Collapse()

expand()

Expand the control.

Source code in flaui/core/patterns/expand_collapse_pattern.py
@handle_csharp_exceptions
def expand(self) -> None:
    """Expand the control."""
    self.raw_pattern.Expand()

GridItemPattern

Bases: PatternBase

Represents the UI Automation GridItem pattern for a single cell within a grid.

column property

Return the zero-based column index of the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the column index.

column_span property

Return the number of columns the cell spans.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the column span.

containing_grid property

Return the grid that contains the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the containing grid element.

row property

Return the zero-based row index of the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the row index.

row_span property

Return the number of rows the cell spans.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the row span.

GridPattern

Bases: PatternBase

Represents the UI Automation Grid pattern for controls arranged in a grid of cells.

column_count property

Return the number of columns in the grid.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the column count.

row_count property

Return the number of rows in the grid.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the row count.

get_item(row, column)

Return the cell at the given zero-based row and column.

Parameters:

Name Type Description Default
row int

Zero-based row index.

required
column int

Zero-based column index.

required

Returns:

Type Description
AutomationElement

The :class:AutomationElement at the requested cell.

Source code in flaui/core/patterns/grid_pattern.py
@handle_csharp_exceptions
def get_item(self, row: int, column: int) -> AutomationElement:
    """Return the cell at the given zero-based row and column.

    :param row: Zero-based row index.
    :param column: Zero-based column index.
    :return: The :class:`AutomationElement` at the requested cell.
    """
    return AutomationElement(raw_element=self.raw_pattern.GetItem(row, column))

InvokePattern

Bases: PatternBase

Represents the UI Automation Invoke pattern for controls that perform a single action.

invoke()

Invoke the control (perform its primary action).

Source code in flaui/core/patterns/invoke_pattern.py
@handle_csharp_exceptions
def invoke(self) -> None:
    """Invoke the control (perform its primary action)."""
    self.raw_pattern.Invoke()

ItemContainerPattern

Bases: PatternBase

Represents the UI Automation ItemContainer pattern for efficient item lookup in containers.

find_item_by_property(start_after, property_id, value)

Find an item by a property value, optionally starting after a given item.

Parameters:

Name Type Description Default
start_after Optional['AutomationElement']

The item to start searching after, or None to start at the beginning.

required
property_id Any

The C# PropertyId to match (or None to find any next item).

required
value Any

The property value to match (or None).

required

Returns:

Type Description
Optional['AutomationElement']

The matching :class:~flaui.core.automation_elements.AutomationElement, or None.

Source code in flaui/core/patterns/item_container_pattern.py
@handle_csharp_exceptions
def find_item_by_property(
    self, start_after: Optional["AutomationElement"], property_id: Any, value: Any
) -> Optional["AutomationElement"]:
    """Find an item by a property value, optionally starting after a given item.

    :param start_after: The item to start searching after, or ``None`` to start at the beginning.
    :param property_id: The C# ``PropertyId`` to match (or ``None`` to find any next item).
    :param value: The property value to match (or ``None``).
    :return: The matching :class:`~flaui.core.automation_elements.AutomationElement`, or ``None``.
    """
    from flaui.core.automation_elements import AutomationElement

    raw_start = None if start_after is None else start_after.raw_element
    result = self.raw_pattern.FindItemByProperty(raw_start, property_id, value)
    return None if result is None else AutomationElement(raw_element=result)

LegacyIAccessiblePattern

Bases: PatternBase

Represents the UI Automation LegacyIAccessible pattern bridging to MSAA IAccessible.

child_id property

Return the MSAA child id of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the child id.

default_action property

Return the element's default action description.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the default action.

description property

Return the element's description.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the description.

help property

Return the element's help text.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the help text.

keyboard_shortcut property

Return the element's keyboard shortcut.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the keyboard shortcut.

name property

Return the element's MSAA name.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the name.

role property

Return the element's MSAA role.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the AccessibilityRole value.

selection property

Return the selected child elements.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selected elements.

state property

Return the element's MSAA state.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the AccessibilityState value.

value property

Return the element's MSAA value.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the value string.

do_default_action()

Perform the element's default action.

Source code in flaui/core/patterns/legacy_i_accessible_pattern.py
@handle_csharp_exceptions
def do_default_action(self) -> None:
    """Perform the element's default action."""
    self.raw_pattern.DoDefaultAction()

select(flags_select)

Modify the selection using MSAA SELFLAG flags.

Parameters:

Name Type Description Default
flags_select int

The MSAA SELFLAG bitmask describing the selection change.

required
Source code in flaui/core/patterns/legacy_i_accessible_pattern.py
@handle_csharp_exceptions
def select(self, flags_select: int) -> None:
    """Modify the selection using MSAA ``SELFLAG`` flags.

    :param flags_select: The MSAA ``SELFLAG`` bitmask describing the selection change.
    """
    self.raw_pattern.Select(flags_select)

set_value(value)

Set the element's value.

Parameters:

Name Type Description Default
value str

The value to set.

required
Source code in flaui/core/patterns/legacy_i_accessible_pattern.py
@handle_csharp_exceptions
def set_value(self, value: str) -> None:
    """Set the element's value.

    :param value: The value to set.
    """
    self.raw_pattern.SetValue(value)

MultipleViewPattern

Bases: PatternBase

Represents the UI Automation MultipleView pattern for controls with several presentations.

current_view property

Return the identifier of the current view.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the current view id.

supported_views property

Return the identifiers of all supported views.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the supported view ids.

get_view_name(view)

Return the localized name of a view.

Parameters:

Name Type Description Default
view int

The view identifier.

required

Returns:

Type Description
str

The view's localized name.

Source code in flaui/core/patterns/multiple_view_pattern.py
@handle_csharp_exceptions
def get_view_name(self, view: int) -> str:
    """Return the localized name of a view.

    :param view: The view identifier.
    :return: The view's localized name.
    """
    return self.raw_pattern.GetViewName(view)

set_current_view(view)

Switch the control to the given view.

Parameters:

Name Type Description Default
view int

The view identifier to switch to.

required
Source code in flaui/core/patterns/multiple_view_pattern.py
@handle_csharp_exceptions
def set_current_view(self, view: int) -> None:
    """Switch the control to the given view.

    :param view: The view identifier to switch to.
    """
    self.raw_pattern.SetCurrentView(view)

ObjectModelPattern

Bases: PatternBase

Represents the UI Automation ObjectModel pattern, exposing a control's underlying object model.

get_underlying_object_model()

Return the control's underlying object model.

Returns:

Type Description
Any

The native object model (a COM/.NET object specific to the control).

Source code in flaui/core/patterns/object_model_pattern.py
@handle_csharp_exceptions
def get_underlying_object_model(self) -> Any:
    """Return the control's underlying object model.

    :return: The native object model (a COM/.NET object specific to the control).
    """
    return self.raw_pattern.GetUnderlyingObjectModel()

PatternBase

Bases: BaseModel, ABC

Base model wrapping a native C# FlaUI pattern object.

validate_pattern_exists(v, info)

Validate the native pattern object exists.

Parameters:

Name Type Description Default
v Any

Raw C# pattern object.

required
info ValidationInfo

Pydantic validation info.

required

Returns:

Type Description
Any

The validated raw pattern object.

Raises:

Type Description
PatternNotSupportedException

If the pattern object is None.

Source code in flaui/core/patterns/pattern_base.py
@field_validator("raw_pattern")
def validate_pattern_exists(cls, v: Any, info: ValidationInfo) -> Any:
    """Validate the native pattern object exists.

    :param v: Raw C# pattern object.
    :param info: Pydantic validation info.
    :raises PatternNotSupportedException: If the pattern object is ``None``.
    :return: The validated raw pattern object.
    """
    if v is None:
        raise PatternNotSupportedException("Pattern is not supported by this element")
    return v

Patterns

Bases: BaseModel

Provides typed access to the UI Automation patterns of an element.

annotation property

Access the Annotation pattern.

Returns:

Type Description
AutomationPattern[AnnotationPattern]

The Annotation pattern accessor.

dock property

Access the Dock pattern.

Returns:

Type Description
AutomationPattern[DockPattern]

The Dock pattern accessor.

drag property

Access the Drag pattern.

Returns:

Type Description
AutomationPattern[DragPattern]

The Drag pattern accessor.

drop_target property

Access the DropTarget pattern.

Returns:

Type Description
AutomationPattern[DropTargetPattern]

The DropTarget pattern accessor.

expand_collapse property

Access the ExpandCollapse pattern.

Returns:

Type Description
AutomationPattern[ExpandCollapsePattern]

The ExpandCollapse pattern accessor.

grid property

Access the Grid pattern.

Returns:

Type Description
AutomationPattern[GridPattern]

The Grid pattern accessor.

grid_item property

Access the GridItem pattern.

Returns:

Type Description
AutomationPattern[GridItemPattern]

The GridItem pattern accessor.

invoke property

Access the Invoke pattern.

Returns:

Type Description
AutomationPattern[InvokePattern]

The Invoke pattern accessor.

item_container property

Access the ItemContainer pattern.

Returns:

Type Description
AutomationPattern[ItemContainerPattern]

The ItemContainer pattern accessor.

legacy_i_accessible property

Access the LegacyIAccessible pattern.

Returns:

Type Description
AutomationPattern[LegacyIAccessiblePattern]

The LegacyIAccessible pattern accessor.

multiple_view property

Access the MultipleView pattern.

Returns:

Type Description
AutomationPattern[MultipleViewPattern]

The MultipleView pattern accessor.

object_model property

Access the ObjectModel pattern.

Returns:

Type Description
AutomationPattern[ObjectModelPattern]

The ObjectModel pattern accessor.

range_value property

Access the RangeValue pattern.

Returns:

Type Description
AutomationPattern[RangeValuePattern]

The RangeValue pattern accessor.

scroll property

Access the Scroll pattern.

Returns:

Type Description
AutomationPattern[ScrollPattern]

The Scroll pattern accessor.

scroll_item property

Access the ScrollItem pattern.

Returns:

Type Description
AutomationPattern[ScrollItemPattern]

The ScrollItem pattern accessor.

selection property

Access the Selection pattern.

Returns:

Type Description
AutomationPattern[SelectionPattern]

The Selection pattern accessor.

selection2 property

Access the Selection2 pattern.

Returns:

Type Description
AutomationPattern[Selection2Pattern]

The Selection2 pattern accessor.

selection_item property

Access the SelectionItem pattern.

Returns:

Type Description
AutomationPattern[SelectionItemPattern]

The SelectionItem pattern accessor.

spreadsheet property

Access the Spreadsheet pattern.

Returns:

Type Description
AutomationPattern[SpreadsheetPattern]

The Spreadsheet pattern accessor.

spreadsheet_item property

Access the SpreadsheetItem pattern.

Returns:

Type Description
AutomationPattern[SpreadsheetItemPattern]

The SpreadsheetItem pattern accessor.

styles property

Access the Styles pattern.

Returns:

Type Description
AutomationPattern[StylesPattern]

The Styles pattern accessor.

synchronized_input property

Access the SynchronizedInput pattern.

Returns:

Type Description
AutomationPattern[SynchronizedInputPattern]

The SynchronizedInput pattern accessor.

table property

Access the Table pattern.

Returns:

Type Description
AutomationPattern[TablePattern]

The Table pattern accessor.

table_item property

Access the TableItem pattern.

Returns:

Type Description
AutomationPattern[TableItemPattern]

The TableItem pattern accessor.

text property

Access the Text pattern.

Returns:

Type Description
AutomationPattern[TextPattern]

The Text pattern accessor.

text2 property

Access the Text2 pattern.

Returns:

Type Description
AutomationPattern[Text2Pattern]

The Text2 pattern accessor.

text_child property

Access the TextChild pattern.

Returns:

Type Description
AutomationPattern[TextChildPattern]

The TextChild pattern accessor.

text_edit property

Access the TextEdit pattern.

Returns:

Type Description
AutomationPattern[TextEditPattern]

The TextEdit pattern accessor.

toggle property

Access the Toggle pattern.

Returns:

Type Description
AutomationPattern[TogglePattern]

The Toggle pattern accessor.

transform property

Access the Transform pattern.

Returns:

Type Description
AutomationPattern[TransformPattern]

The Transform pattern accessor.

transform2 property

Access the Transform2 pattern.

Returns:

Type Description
AutomationPattern[Transform2Pattern]

The Transform2 pattern accessor.

value property

Access the Value pattern.

Returns:

Type Description
AutomationPattern[ValuePattern]

The Value pattern accessor.

virtualized_item property

Access the VirtualizedItem pattern.

Returns:

Type Description
AutomationPattern[VirtualizedItemPattern]

The VirtualizedItem pattern accessor.

window property

Access the Window pattern.

Returns:

Type Description
AutomationPattern[WindowPattern]

The Window pattern accessor.

RangeValuePattern

Bases: PatternBase

Represents the UI Automation RangeValue pattern for controls with a numeric range (e.g. sliders).

is_read_only property

Return whether the value is read-only.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the read-only flag.

large_change property

Return the value added or subtracted on a large change.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the large-change amount.

maximum property

Return the maximum value of the range.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the maximum value.

minimum property

Return the minimum value of the range.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the minimum value.

small_change property

Return the value added or subtracted on a small change.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the small-change amount.

value property

Return the current value.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the current value.

set_value(value)

Set the control's value.

Parameters:

Name Type Description Default
value float

The numeric value to set.

required
Source code in flaui/core/patterns/range_value_pattern.py
@handle_csharp_exceptions
def set_value(self, value: float) -> None:
    """Set the control's value.

    :param value: The numeric value to set.
    """
    self.raw_pattern.SetValue(value)

ScrollItemPattern

Bases: PatternBase

Represents the UI Automation ScrollItem pattern for items that can scroll into view.

scroll_into_view()

Scroll the item into the visible region of its container.

Source code in flaui/core/patterns/scroll_item_pattern.py
@handle_csharp_exceptions
def scroll_into_view(self) -> None:
    """Scroll the item into the visible region of its container."""
    self.raw_pattern.ScrollIntoView()

ScrollPattern

Bases: PatternBase

Represents the UI Automation Scroll pattern for controls that scroll their content.

horizontal_scroll_percent property

Return the horizontal scroll position as a percentage.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the horizontal scroll percent.

horizontal_view_size property

Return the horizontal viewport size as a percentage of the total content.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the horizontal view size.

horizontally_scrollable property

Return whether the control can scroll horizontally.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the horizontal-scrollable flag.

vertical_scroll_percent property

Return the vertical scroll position as a percentage.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the vertical scroll percent.

vertical_view_size property

Return the vertical viewport size as a percentage of the total content.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the vertical view size.

vertically_scrollable property

Return whether the control can scroll vertically.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the vertical-scrollable flag.

scroll(horizontal_amount, vertical_amount)

Scroll the content by the given horizontal and vertical amounts.

Parameters:

Name Type Description Default
horizontal_amount ScrollAmount

The horizontal scroll amount.

required
vertical_amount ScrollAmount

The vertical scroll amount.

required
Source code in flaui/core/patterns/scroll_pattern.py
@handle_csharp_exceptions
def scroll(self, horizontal_amount: ScrollAmount, vertical_amount: ScrollAmount) -> None:
    """Scroll the content by the given horizontal and vertical amounts.

    :param horizontal_amount: The horizontal scroll amount.
    :param vertical_amount: The vertical scroll amount.
    """
    self.raw_pattern.Scroll(horizontal_amount.value, vertical_amount.value)

set_scroll_percent(horizontal_percent, vertical_percent)

Set the scroll position as horizontal and vertical percentages.

Parameters:

Name Type Description Default
horizontal_percent float

The horizontal scroll position (0-100), or -1 for no change.

required
vertical_percent float

The vertical scroll position (0-100), or -1 for no change.

required
Source code in flaui/core/patterns/scroll_pattern.py
@handle_csharp_exceptions
def set_scroll_percent(self, horizontal_percent: float, vertical_percent: float) -> None:
    """Set the scroll position as horizontal and vertical percentages.

    :param horizontal_percent: The horizontal scroll position (0-100), or ``-1`` for no change.
    :param vertical_percent: The vertical scroll position (0-100), or ``-1`` for no change.
    """
    self.raw_pattern.SetScrollPercent(horizontal_percent, vertical_percent)

Selection2Pattern

Bases: SelectionPattern

Extends the Selection pattern with current/first/last selected item and item-count info.

current_selected_item property

Return the currently selected item.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the current selected element.

first_selected_item property

Return the first selected item.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the first selected element.

item_count property

Return the number of selected items.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selected-item count.

last_selected_item property

Return the last selected item.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the last selected element.

SelectionItemPattern

Bases: PatternBase

Represents the UI Automation SelectionItem pattern for individually selectable items.

is_selected property

Return whether the item is selected.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selected flag.

selection_container property

Return the container that holds the item.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selection container element.

add_to_selection()

Add the item to the current selection.

Source code in flaui/core/patterns/selection_item_pattern.py
@handle_csharp_exceptions
def add_to_selection(self) -> None:
    """Add the item to the current selection."""
    self.raw_pattern.AddToSelection()

remove_from_selection()

Remove the item from the current selection.

Source code in flaui/core/patterns/selection_item_pattern.py
@handle_csharp_exceptions
def remove_from_selection(self) -> None:
    """Remove the item from the current selection."""
    self.raw_pattern.RemoveFromSelection()

select()

Select the item, deselecting any other selected items.

Source code in flaui/core/patterns/selection_item_pattern.py
@handle_csharp_exceptions
def select(self) -> None:
    """Select the item, deselecting any other selected items."""
    self.raw_pattern.Select()

SelectionPattern

Bases: PatternBase

Represents the UI Automation Selection pattern for containers of selectable items.

can_select_multiple property

Return whether the container allows multiple items to be selected.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the multi-select flag.

is_selection_required property

Return whether the container requires at least one item to be selected.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selection-required flag.

selection property

Return the currently selected items.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the selected elements.

SpreadsheetItemPattern

Bases: PatternBase

Represents the UI Automation SpreadsheetItem pattern for a single spreadsheet cell.

annotation_objects property

Return the annotation elements associated with the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the annotation elements.

annotation_types property

Return the annotation type identifiers associated with the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the annotation types.

formula property

Return the formula of the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the formula string.

SpreadsheetPattern

Bases: PatternBase

Represents the UI Automation Spreadsheet pattern for accessing cells by name.

get_item_by_name(name)

Return the spreadsheet cell with the given name.

Parameters:

Name Type Description Default
name str

The name of the cell (e.g. "A1").

required

Returns:

Type Description
Any

The matching :class:~flaui.core.automation_elements.AutomationElement.

Source code in flaui/core/patterns/spreadsheet_pattern.py
@handle_csharp_exceptions
def get_item_by_name(self, name: str) -> Any:
    """Return the spreadsheet cell with the given name.

    :param name: The name of the cell (e.g. ``"A1"``).
    :return: The matching :class:`~flaui.core.automation_elements.AutomationElement`.
    """
    from flaui.core.automation_elements import AutomationElement

    return AutomationElement(raw_element=self.raw_pattern.GetItemByName(name))

StylesPattern

Bases: PatternBase

Represents the UI Automation Styles pattern for elements with visual styling (e.g. cells).

extended_properties property

Return extended style properties as a string.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the extended properties.

fill_color property

Return the fill color of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the fill color (ARGB int).

fill_pattern_color property

Return the fill pattern color of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the fill pattern color (ARGB int).

fill_pattern_style property

Return the fill pattern style name.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the fill pattern style.

shape property

Return the shape of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the shape.

style property

Return the style identifier of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the StyleType value.

style_name property

Return the localized style name of the element.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the style name.

SynchronizedInputPattern

Bases: PatternBase

Represents the UI Automation SynchronizedInput pattern for coordinating input events.

cancel()

Cancel listening for synchronized input.

Source code in flaui/core/patterns/synchronized_input_pattern.py
@handle_csharp_exceptions
def cancel(self) -> None:
    """Cancel listening for synchronized input."""
    self.raw_pattern.Cancel()

start_listening(input_type)

Begin listening for the given type of synchronized input.

Parameters:

Name Type Description Default
input_type SynchronizedInputType

The type of input event to listen for.

required
Source code in flaui/core/patterns/synchronized_input_pattern.py
@handle_csharp_exceptions
def start_listening(self, input_type: SynchronizedInputType) -> None:
    """Begin listening for the given type of synchronized input.

    :param input_type: The type of input event to listen for.
    """
    self.raw_pattern.StartListening(input_type.value)

TableItemPattern

Bases: PatternBase

Represents the UI Automation TableItem pattern for a cell that knows its header items.

column_header_items property

Return the column header items associated with the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the column header items.

row_header_items property

Return the row header items associated with the cell.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the row header items.

TablePattern

Bases: PatternBase

Represents the UI Automation Table pattern for grids that expose header information.

column_headers property

Return the column header elements of the table.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the column header elements.

row_headers property

Return the row header elements of the table.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the row header elements.

row_or_column_major property

Return whether the table is row-major or column-major.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the RowOrColumnMajor value.

Text2Pattern

Bases: TextPattern

Extends the Text pattern with caret and annotation range lookups.

get_caret_range()

Return the text range of the caret and whether the caret is active.

Returns:

Type Description
Tuple[TextRange, bool]

A tuple (caret_range, is_active).

Source code in flaui/core/patterns/text2_pattern.py
@handle_csharp_exceptions
def get_caret_range(self) -> Tuple[TextRange, bool]:
    """Return the text range of the caret and whether the caret is active.

    :return: A tuple ``(caret_range, is_active)``.
    """
    raw_range, is_active = self.raw_pattern.GetCaretRange()
    return TextRange(raw_text_range=raw_range), is_active

range_from_annotation(annotation)

Return the text range associated with an annotation element.

Parameters:

Name Type Description Default
annotation 'AutomationElement'

The annotation element.

required

Returns:

Type Description
TextRange

A :class:~flaui.core.text_range.TextRange for the annotation.

Source code in flaui/core/patterns/text2_pattern.py
@handle_csharp_exceptions
def range_from_annotation(self, annotation: "AutomationElement") -> TextRange:
    """Return the text range associated with an annotation element.

    :param annotation: The annotation element.
    :return: A :class:`~flaui.core.text_range.TextRange` for the annotation.
    """
    return TextRange(raw_text_range=self.raw_pattern.RangeFromAnnotation(annotation.raw_element))

TextChildPattern

Bases: PatternBase

Represents the UI Automation TextChild pattern for elements embedded inside text content.

text_container property

Return the nearest ancestor that supports the Text pattern.

Returns:

Type Description
Any

The containing :class:~flaui.core.automation_elements.AutomationElement.

text_range property

Return the text range that encloses this child element.

Returns:

Type Description
TextRange

A :class:~flaui.core.text_range.TextRange for the element.

TextEditPattern

Bases: TextPattern

Extends the Text pattern with access to in-progress text composition (IME) ranges.

get_active_composition()

Return the text range of the active text composition, if any.

Returns:

Type Description
Optional[TextRange]

The active composition :class:~flaui.core.text_range.TextRange, or None.

Source code in flaui/core/patterns/text_edit_pattern.py
@handle_csharp_exceptions
def get_active_composition(self) -> Optional[TextRange]:
    """Return the text range of the active text composition, if any.

    :return: The active composition :class:`~flaui.core.text_range.TextRange`, or ``None``.
    """
    result = self.raw_pattern.GetActiveComposition()
    return None if result is None else TextRange(raw_text_range=result)

get_conversion_target()

Return the text range of the current conversion target, if any.

Returns:

Type Description
Optional[TextRange]

The conversion target :class:~flaui.core.text_range.TextRange, or None.

Source code in flaui/core/patterns/text_edit_pattern.py
@handle_csharp_exceptions
def get_conversion_target(self) -> Optional[TextRange]:
    """Return the text range of the current conversion target, if any.

    :return: The conversion target :class:`~flaui.core.text_range.TextRange`, or ``None``.
    """
    result = self.raw_pattern.GetConversionTarget()
    return None if result is None else TextRange(raw_text_range=result)

TextPattern

Bases: PatternBase

Represents the UI Automation Text pattern for controls that expose rich text content.

document_range property

Return a text range spanning the entire document.

Returns:

Type Description
TextRange

A :class:~flaui.core.text_range.TextRange over the whole document.

supported_text_selection property

Return the kind of text selection the control supports.

Returns:

Type Description
SupportedTextSelection

The supported text selection mode.

get_selection()

Return the currently selected text ranges.

Returns:

Type Description
List[TextRange]

A list of selected :class:~flaui.core.text_range.TextRange objects.

Source code in flaui/core/patterns/text_pattern.py
@handle_csharp_exceptions
def get_selection(self) -> List[TextRange]:
    """Return the currently selected text ranges.

    :return: A list of selected :class:`~flaui.core.text_range.TextRange` objects.
    """
    return [TextRange(raw_text_range=_) for _ in self.raw_pattern.GetSelection()]

get_visible_ranges()

Return the text ranges that are currently visible.

Returns:

Type Description
List[TextRange]

A list of visible :class:~flaui.core.text_range.TextRange objects.

Source code in flaui/core/patterns/text_pattern.py
@handle_csharp_exceptions
def get_visible_ranges(self) -> List[TextRange]:
    """Return the text ranges that are currently visible.

    :return: A list of visible :class:`~flaui.core.text_range.TextRange` objects.
    """
    return [TextRange(raw_text_range=_) for _ in self.raw_pattern.GetVisibleRanges()]

range_from_child(child)

Return the text range that encloses a child element.

Parameters:

Name Type Description Default
child 'AutomationElement'

The child element to locate.

required

Returns:

Type Description
TextRange

A :class:~flaui.core.text_range.TextRange enclosing the child.

Source code in flaui/core/patterns/text_pattern.py
@handle_csharp_exceptions
def range_from_child(self, child: "AutomationElement") -> TextRange:
    """Return the text range that encloses a child element.

    :param child: The child element to locate.
    :return: A :class:`~flaui.core.text_range.TextRange` enclosing the child.
    """
    return TextRange(raw_text_range=self.raw_pattern.RangeFromChild(child.raw_element))

range_from_point(point)

Return the degenerate text range nearest to a screen point.

Parameters:

Name Type Description Default
point Point

The screen point to locate.

required

Returns:

Type Description
TextRange

A :class:~flaui.core.text_range.TextRange at the point.

Source code in flaui/core/patterns/text_pattern.py
@handle_csharp_exceptions
def range_from_point(self, point: Point) -> TextRange:
    """Return the degenerate text range nearest to a screen point.

    :param point: The screen point to locate.
    :return: A :class:`~flaui.core.text_range.TextRange` at the point.
    """
    return TextRange(raw_text_range=self.raw_pattern.RangeFromPoint(point.cs_object))

TogglePattern

Bases: PatternBase

Represents the UI Automation Toggle pattern for controls that cycle through states.

toggle_state property

Return the current toggle state.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the ToggleState value.

toggle()

Cycle the control to its next toggle state.

Source code in flaui/core/patterns/toggle_pattern.py
@handle_csharp_exceptions
def toggle(self) -> None:
    """Cycle the control to its next toggle state."""
    self.raw_pattern.Toggle()

Transform2Pattern

Bases: TransformPattern

Extends the Transform pattern with zoom capabilities.

can_zoom property

Return whether the control can be zoomed.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-zoom flag.

zoom_level property

Return the current zoom level.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the zoom level.

zoom_maximum property

Return the maximum zoom level.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the maximum zoom level.

zoom_minimum property

Return the minimum zoom level.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the minimum zoom level.

zoom(zoom)

Zoom the control to the given level.

Parameters:

Name Type Description Default
zoom float

The target zoom level.

required
Source code in flaui/core/patterns/transform2_pattern.py
@handle_csharp_exceptions
def zoom(self, zoom: float) -> None:
    """Zoom the control to the given level.

    :param zoom: The target zoom level.
    """
    self.raw_pattern.Zoom(zoom)

zoom_by_unit(zoom_unit)

Zoom the control by a discrete unit.

Parameters:

Name Type Description Default
zoom_unit ZoomUnit

The zoom unit (increment/decrement amount).

required
Source code in flaui/core/patterns/transform2_pattern.py
@handle_csharp_exceptions
def zoom_by_unit(self, zoom_unit: ZoomUnit) -> None:
    """Zoom the control by a discrete unit.

    :param zoom_unit: The zoom unit (increment/decrement amount).
    """
    self.raw_pattern.ZoomByUnit(zoom_unit.value)

TransformPattern

Bases: PatternBase

Represents the UI Automation Transform pattern for movable, resizable, rotatable controls.

can_move property

Return whether the control can be moved.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-move flag.

can_resize property

Return whether the control can be resized.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-resize flag.

can_rotate property

Return whether the control can be rotated.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-rotate flag.

move(x, y)

Move the control to the given screen coordinates.

Parameters:

Name Type Description Default
x float

The target x-coordinate.

required
y float

The target y-coordinate.

required
Source code in flaui/core/patterns/transform_pattern.py
@handle_csharp_exceptions
def move(self, x: float, y: float) -> None:
    """Move the control to the given screen coordinates.

    :param x: The target x-coordinate.
    :param y: The target y-coordinate.
    """
    self.raw_pattern.Move(x, y)

resize(width, height)

Resize the control to the given dimensions.

Parameters:

Name Type Description Default
width float

The target width.

required
height float

The target height.

required
Source code in flaui/core/patterns/transform_pattern.py
@handle_csharp_exceptions
def resize(self, width: float, height: float) -> None:
    """Resize the control to the given dimensions.

    :param width: The target width.
    :param height: The target height.
    """
    self.raw_pattern.Resize(width, height)

rotate(degrees)

Rotate the control by the given number of degrees.

Parameters:

Name Type Description Default
degrees float

The rotation in degrees.

required
Source code in flaui/core/patterns/transform_pattern.py
@handle_csharp_exceptions
def rotate(self, degrees: float) -> None:
    """Rotate the control by the given number of degrees.

    :param degrees: The rotation in degrees.
    """
    self.raw_pattern.Rotate(degrees)

ValuePattern

Bases: PatternBase

Represents the UI Automation Value pattern for reading and setting a control's text value.

is_read_only property

Return whether the value is read-only.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the read-only flag.

value property

Return the current value.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the value string.

set_value(value)

Set the control's value.

Parameters:

Name Type Description Default
value str

The value to set.

required
Source code in flaui/core/patterns/value_pattern.py
@handle_csharp_exceptions
def set_value(self, value: str) -> None:
    """Set the control's value.

    :param value: The value to set.
    """
    self.raw_pattern.SetValue(value)

VirtualizedItemPattern

Bases: PatternBase

Represents the UI Automation VirtualizedItem pattern for items that can be realized on demand.

realize()

Realize the virtualized item, making it a full member of the automation tree.

Source code in flaui/core/patterns/virtualized_item_pattern.py
@handle_csharp_exceptions
def realize(self) -> None:
    """Realize the virtualized item, making it a full member of the automation tree."""
    self.raw_pattern.Realize()

WindowPattern

Bases: PatternBase

Represents the UI Automation Window pattern for top-level and child windows.

can_maximize property

Return whether the window can be maximized.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-maximize flag.

can_minimize property

Return whether the window can be minimized.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the can-minimize flag.

is_modal property

Return whether the window is modal.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the modal flag.

is_topmost property

Return whether the window is top-most.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the top-most flag.

window_interaction_state property

Return the window's current interaction state.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the WindowInteractionState value.

window_visual_state property

Return the window's current visual state.

Returns:

Type Description
AutomationProperty

An :class:AutomationProperty wrapping the WindowVisualState value.

close()

Close the window.

Source code in flaui/core/patterns/window_pattern.py
@handle_csharp_exceptions
def close(self) -> None:
    """Close the window."""
    self.raw_pattern.Close()

set_window_visual_state(state)

Set the window's visual state.

Parameters:

Name Type Description Default
state WindowVisualState

The desired visual state (normal, maximized, or minimized).

required
Source code in flaui/core/patterns/window_pattern.py
@handle_csharp_exceptions
def set_window_visual_state(self, state: WindowVisualState) -> None:
    """Set the window's visual state.

    :param state: The desired visual state (normal, maximized, or minimized).
    """
    self.raw_pattern.SetWindowVisualState(state.value)

wait_for_input_idle(milliseconds)

Wait until the window is ready to accept input, or the timeout elapses.

Parameters:

Name Type Description Default
milliseconds int

The maximum time to wait, in milliseconds.

required

Returns:

Type Description
bool

True if the window became idle within the timeout, else False.

Source code in flaui/core/patterns/window_pattern.py
@handle_csharp_exceptions
def wait_for_input_idle(self, milliseconds: int) -> bool:
    """Wait until the window is ready to accept input, or the timeout elapses.

    :param milliseconds: The maximum time to wait, in milliseconds.
    :return: ``True`` if the window became idle within the timeout, else ``False``.
    """
    return self.raw_pattern.WaitForInputIdle(milliseconds)

Text ranges

The Text patterns (TextPattern, Text2Pattern, TextEditPattern, TextChildPattern) return TextRange objects, the Python wrapper around C# ITextRange.

flaui.core.text_range

Python wrapper for the C# FlaUI.Core.ITextRange type.

A text range represents a contiguous span of text within a control that supports the Text pattern. The wrapper mirrors ITextRange one-to-one; the native object stays reachable via :attr:TextRange.raw_text_range.

TextRange

Bases: BaseModel

Represents a span of text within a Text-pattern control (mirrors C# ITextRange).

add_to_selection()

Add the text range to the current selection.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def add_to_selection(self) -> None:
    """Add the text range to the current selection."""
    self.raw_text_range.AddToSelection()

clone()

Return a copy of the text range.

Returns:

Type Description
'TextRange'

A new :class:TextRange with the same span.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def clone(self) -> "TextRange":
    """Return a copy of the text range.

    :return: A new :class:`TextRange` with the same span.
    """
    return TextRange(raw_text_range=self.raw_text_range.Clone())

compare(range)

Return whether this range spans the same text as another.

Parameters:

Name Type Description Default
range 'TextRange'

The range to compare against.

required

Returns:

Type Description
bool

True if both ranges have identical endpoints.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def compare(self, range: "TextRange") -> bool:
    """Return whether this range spans the same text as another.

    :param range: The range to compare against.
    :return: ``True`` if both ranges have identical endpoints.
    """
    return self.raw_text_range.Compare(range.raw_text_range)

compare_endpoints(src_endpoint, target_range, target_endpoint)

Compare an endpoint of this range with an endpoint of another range.

Parameters:

Name Type Description Default
src_endpoint TextPatternRangeEndpoint

The endpoint of this range to compare.

required
target_range 'TextRange'

The other range.

required
target_endpoint TextPatternRangeEndpoint

The endpoint of the other range to compare.

required

Returns:

Type Description
int

Negative, zero, or positive if this endpoint is before, at, or after the target.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def compare_endpoints(
    self,
    src_endpoint: TextPatternRangeEndpoint,
    target_range: "TextRange",
    target_endpoint: TextPatternRangeEndpoint,
) -> int:
    """Compare an endpoint of this range with an endpoint of another range.

    :param src_endpoint: The endpoint of this range to compare.
    :param target_range: The other range.
    :param target_endpoint: The endpoint of the other range to compare.
    :return: Negative, zero, or positive if this endpoint is before, at, or after the target.
    """
    return self.raw_text_range.CompareEndpoints(
        src_endpoint.value, target_range.raw_text_range, target_endpoint.value
    )

expand_to_enclosing_unit(text_unit)

Expand the range to the nearest enclosing unit boundary.

Parameters:

Name Type Description Default
text_unit TextUnit

The text unit to expand to.

required
Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def expand_to_enclosing_unit(self, text_unit: TextUnit) -> None:
    """Expand the range to the nearest enclosing unit boundary.

    :param text_unit: The text unit to expand to.
    """
    self.raw_text_range.ExpandToEnclosingUnit(text_unit.value)

find_attribute(attribute, value, backward)

Find a sub-range with the given text attribute value.

Parameters:

Name Type Description Default
attribute Any

The C# TextAttributeId to search for.

required
value Any

The attribute value to match.

required
backward bool

Search backward from the end when True.

required

Returns:

Type Description
Optional['TextRange']

The matching :class:TextRange, or None if not found.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def find_attribute(self, attribute: Any, value: Any, backward: bool) -> Optional["TextRange"]:
    """Find a sub-range with the given text attribute value.

    :param attribute: The C# ``TextAttributeId`` to search for.
    :param value: The attribute value to match.
    :param backward: Search backward from the end when ``True``.
    :return: The matching :class:`TextRange`, or ``None`` if not found.
    """
    result = self.raw_text_range.FindAttribute(attribute, value, backward)
    return None if result is None else TextRange(raw_text_range=result)

find_text(text, backward, ignore_case)

Find a sub-range containing the given text.

Parameters:

Name Type Description Default
text str

The text to find.

required
backward bool

Search backward from the end when True.

required
ignore_case bool

Match case-insensitively when True.

required

Returns:

Type Description
Optional['TextRange']

The matching :class:TextRange, or None if not found.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def find_text(self, text: str, backward: bool, ignore_case: bool) -> Optional["TextRange"]:
    """Find a sub-range containing the given text.

    :param text: The text to find.
    :param backward: Search backward from the end when ``True``.
    :param ignore_case: Match case-insensitively when ``True``.
    :return: The matching :class:`TextRange`, or ``None`` if not found.
    """
    result = self.raw_text_range.FindText(text, backward, ignore_case)
    return None if result is None else TextRange(raw_text_range=result)

get_attribute_value(attribute)

Return the value of a text attribute over the range.

Parameters:

Name Type Description Default
attribute Any

The C# TextAttributeId to read.

required

Returns:

Type Description
Any

The attribute value (a mixed value if the attribute varies over the range).

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def get_attribute_value(self, attribute: Any) -> Any:
    """Return the value of a text attribute over the range.

    :param attribute: The C# ``TextAttributeId`` to read.
    :return: The attribute value (a mixed value if the attribute varies over the range).
    """
    return self.raw_text_range.GetAttributeValue(attribute)

get_bounding_rectangles()

Return the bounding rectangles of the text in the range.

Returns:

Type Description
List[Rectangle]

A list of :class:Rectangle for each line in the range.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def get_bounding_rectangles(self) -> List[Rectangle]:
    """Return the bounding rectangles of the text in the range.

    :return: A list of :class:`Rectangle` for each line in the range.
    """
    return [Rectangle(raw_value=_) for _ in self.raw_text_range.GetBoundingRectangles()]

get_children()

Return the embedded child elements within the range.

Returns:

Type Description
List[Any]

A list of child automation elements.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def get_children(self) -> List[Any]:
    """Return the embedded child elements within the range.

    :return: A list of child automation elements.
    """
    from flaui.core.automation_elements import AutomationElement

    return [AutomationElement(raw_element=_) for _ in self.raw_text_range.GetChildren()]

get_enclosing_element()

Return the innermost element that encloses the range.

Returns:

Type Description
Any

The enclosing :class:~flaui.core.automation_elements.AutomationElement.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def get_enclosing_element(self) -> Any:
    """Return the innermost element that encloses the range.

    :return: The enclosing :class:`~flaui.core.automation_elements.AutomationElement`.
    """
    from flaui.core.automation_elements import AutomationElement

    return AutomationElement(raw_element=self.raw_text_range.GetEnclosingElement())

get_text(max_length=-1)

Return the plain text of the range.

Parameters:

Name Type Description Default
max_length int

Maximum number of characters to return, or -1 for all.

-1

Returns:

Type Description
str

The text of the range.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def get_text(self, max_length: int = -1) -> str:
    """Return the plain text of the range.

    :param max_length: Maximum number of characters to return, or ``-1`` for all.
    :return: The text of the range.
    """
    return self.raw_text_range.GetText(max_length)

move(unit, count)

Move the range by the given number of text units.

Parameters:

Name Type Description Default
unit TextUnit

The unit to move by.

required
count int

The number of units to move (negative moves backward).

required

Returns:

Type Description
int

The number of units actually moved.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def move(self, unit: TextUnit, count: int) -> int:
    """Move the range by the given number of text units.

    :param unit: The unit to move by.
    :param count: The number of units to move (negative moves backward).
    :return: The number of units actually moved.
    """
    return self.raw_text_range.Move(unit.value, count)

move_endpoint_by_range(src_endpoint, target_range, target_endpoint)

Move an endpoint of this range to an endpoint of another range.

Parameters:

Name Type Description Default
src_endpoint TextPatternRangeEndpoint

The endpoint of this range to move.

required
target_range 'TextRange'

The range whose endpoint becomes the new position.

required
target_endpoint TextPatternRangeEndpoint

The endpoint of the target range to move to.

required
Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def move_endpoint_by_range(
    self,
    src_endpoint: TextPatternRangeEndpoint,
    target_range: "TextRange",
    target_endpoint: TextPatternRangeEndpoint,
) -> None:
    """Move an endpoint of this range to an endpoint of another range.

    :param src_endpoint: The endpoint of this range to move.
    :param target_range: The range whose endpoint becomes the new position.
    :param target_endpoint: The endpoint of the target range to move to.
    """
    self.raw_text_range.MoveEndpointByRange(src_endpoint.value, target_range.raw_text_range, target_endpoint.value)

move_endpoint_by_unit(endpoint, unit, count)

Move an endpoint of the range by the given number of text units.

Parameters:

Name Type Description Default
endpoint TextPatternRangeEndpoint

The endpoint to move.

required
unit TextUnit

The unit to move by.

required
count int

The number of units to move (negative moves backward).

required

Returns:

Type Description
int

The number of units actually moved.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def move_endpoint_by_unit(self, endpoint: TextPatternRangeEndpoint, unit: TextUnit, count: int) -> int:
    """Move an endpoint of the range by the given number of text units.

    :param endpoint: The endpoint to move.
    :param unit: The unit to move by.
    :param count: The number of units to move (negative moves backward).
    :return: The number of units actually moved.
    """
    return self.raw_text_range.MoveEndpointByUnit(endpoint.value, unit.value, count)

remove_from_selection()

Remove the text range from the current selection.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def remove_from_selection(self) -> None:
    """Remove the text range from the current selection."""
    self.raw_text_range.RemoveFromSelection()

scroll_into_view(align_to_top)

Scroll the range into view.

Parameters:

Name Type Description Default
align_to_top bool

Align the range to the top of the viewport when True.

required
Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def scroll_into_view(self, align_to_top: bool) -> None:
    """Scroll the range into view.

    :param align_to_top: Align the range to the top of the viewport when ``True``.
    """
    self.raw_text_range.ScrollIntoView(align_to_top)

select()

Select the text range, replacing any existing selection.

Source code in flaui/core/text_range.py
@handle_csharp_exceptions
def select(self) -> None:
    """Select the text range, replacing any existing selection."""
    self.raw_text_range.Select()

validate_text_range_exists(v, info)

Validate the native text range exists.

Parameters:

Name Type Description Default
v Any

Raw C# ITextRange object.

required
info ValidationInfo

Pydantic validation info.

required

Returns:

Type Description
Any

The validated raw text range.

Raises:

Type Description
ElementNotFound

If the text range is None.

Source code in flaui/core/text_range.py
@field_validator("raw_text_range")
def validate_text_range_exists(cls, v: Any, info: ValidationInfo) -> Any:
    """Validate the native text range exists.

    :param v: Raw C# ITextRange object.
    :param info: Pydantic validation info.
    :raises ElementNotFound: If the text range is ``None``.
    :return: The validated raw text range.
    """
    if v is None:
        raise ElementNotFound("Text range does not exist")
    return v