Skip to content

Automation Element

flaui.core.automation_elements.AutomationElement

Bases: ElementBase

UI element which can be used in automation

automation property

The current used automation object as a Python AutomationBase facade.

Returns:

Type Description
AutomationBase

Python UIA2Automation or UIA3Automation wrapper

item_status property

The item status of this element.

Returns:

Type Description
str

Item status value

as_button()

Converts the element to a Button.

Returns:

Type Description
Button

Button element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_button(self) -> Button:
    """Converts the element to a Button.

    :return: Button element
    """
    from FlaUI.Core.AutomationElements import Button as CSButton  # pyright: ignore

    return Button(raw_element=CSButton(self.framework_automation_element))

as_calendar()

Converts the element to a Calendar.

Returns:

Type Description
Calendar

Calendar element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_calendar(self) -> Calendar:
    """Converts the element to a Calendar.

    :return: Calendar element
    """
    from FlaUI.Core.AutomationElements import Calendar as CSCalendar  # pyright: ignore

    return Calendar(raw_element=CSCalendar(self.framework_automation_element))

as_check_box()

Converts the element to a CheckBox.

Returns:

Type Description
CheckBox

CheckBox element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_check_box(self) -> CheckBox:
    """Converts the element to a CheckBox.

    :return: CheckBox element
    """
    from FlaUI.Core.AutomationElements import CheckBox as CSCheckBox  # pyright: ignore

    return CheckBox(raw_element=CSCheckBox(self.framework_automation_element))

as_combo_box()

Converts the element to a ComboBox.

Returns:

Type Description
ComboBox

ComboBox element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_combo_box(self) -> ComboBox:
    """Converts the element to a ComboBox.

    :return: ComboBox element
    """
    from FlaUI.Core.AutomationElements import ComboBox as CSComboBox  # pyright: ignore

    return ComboBox(raw_element=CSComboBox(self.framework_automation_element))

as_data_grid_view()

Converts the element to a DataGridView.

Returns:

Type Description
DataGridView

DataGridView element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_data_grid_view(self) -> DataGridView:
    """Converts the element to a DataGridView.

    :return: DataGridView element
    """
    from FlaUI.Core.AutomationElements import DataGridView as CSDataGridView  # pyright: ignore

    return DataGridView(raw_element=CSDataGridView(self.framework_automation_element))

as_date_time_picker()

Converts the element to a DateTimePicker.

Returns:

Type Description
DateTimePicker

DateTimePicker element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_date_time_picker(self) -> DateTimePicker:
    """Converts the element to a DateTimePicker.

    :return: DateTimePicker element
    """
    from FlaUI.Core.AutomationElements import DateTimePicker as CSDateTimePicker  # pyright: ignore

    return DateTimePicker(raw_element=CSDateTimePicker(self.framework_automation_element))

as_grid()

Converts the element to a Grid.

Returns:

Type Description
Grid

Grid element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_grid(self) -> Grid:
    """Converts the element to a Grid.

    :return: Grid element
    """
    from FlaUI.Core.AutomationElements import Grid as CSGrid  # pyright: ignore

    return Grid(raw_element=CSGrid(self.framework_automation_element))

as_grid_cell()

Converts the element to a GridCell.

Returns:

Type Description
GridCell

GridCell element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_grid_cell(self) -> GridCell:
    """Converts the element to a GridCell.

    :return: GridCell element
    """
    from FlaUI.Core.AutomationElements import GridCell as CSGridCell  # pyright: ignore

    return GridCell(raw_element=CSGridCell(self.framework_automation_element))

as_grid_header_item()

Converts the element to a GridHeaderItem.

Returns:

Type Description
GridHeaderItem

GridHeaderItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_grid_header_item(self) -> GridHeaderItem:
    """Converts the element to a GridHeaderItem.

    :return: GridHeaderItem element
    """
    from FlaUI.Core.AutomationElements import GridHeaderItem as CSGridHeaderItem  # pyright: ignore

    return GridHeaderItem(raw_element=CSGridHeaderItem(self.framework_automation_element))

as_grid_row()

Converts the element to a GridRow.

Returns:

Type Description
GridRow

GridRow element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_grid_row(self) -> GridRow:
    """Converts the element to a GridRow.

    :return: GridRow element
    """
    from FlaUI.Core.AutomationElements import GridRow as CSGridRow  # pyright: ignore

    return GridRow(raw_element=CSGridRow(self.framework_automation_element))

as_horizontal_scroll_bar()

Converts the element to a HorizontalScrollBar.

Returns:

Type Description
HorizontalScrollBar

HorizontalScrollBar element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_horizontal_scroll_bar(self) -> HorizontalScrollBar:
    """Converts the element to a HorizontalScrollBar.

    :return: HorizontalScrollBar element
    """
    from FlaUI.Core.AutomationElements.Scrolling import HorizontalScrollBar as CSHorizontalScrollBar  # pyright: ignore

    return HorizontalScrollBar(raw_element=CSHorizontalScrollBar(self.framework_automation_element))

as_label()

Converts the element to a Label.

Returns:

Type Description
Label

Label element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_label(self) -> Label:
    """Converts the element to a Label.

    :return: Label element
    """
    from FlaUI.Core.AutomationElements import Label as CSLabel  # pyright: ignore

    return Label(raw_element=CSLabel(self.framework_automation_element))

as_list_box()

Converts the element to a ListBox.

Returns:

Type Description
ListBox

ListBox element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_list_box(self) -> ListBox:
    """Converts the element to a ListBox.

    :return: ListBox element
    """
    from FlaUI.Core.AutomationElements import ListBox as CSListBox  # pyright: ignore

    return ListBox(raw_element=CSListBox(self.framework_automation_element))

as_list_box_item()

Converts the element to a ListBoxItem.

Returns:

Type Description
ListBoxItem

ListBoxItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_list_box_item(self) -> ListBoxItem:
    """Converts the element to a ListBoxItem.

    :return: ListBoxItem element
    """
    from FlaUI.Core.AutomationElements import ListBoxItem as CSListBoxItem  # pyright: ignore

    return ListBoxItem(raw_element=CSListBoxItem(self.framework_automation_element))

as_menu()

Converts the element to a Menu.

Returns:

Type Description
Menu

Menu element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_menu(self) -> Menu:
    """Converts the element to a Menu.

    :return: Menu element
    """
    from FlaUI.Core.AutomationElements import Menu as CSMenu  # pyright: ignore

    return Menu(raw_element=CSMenu(self.framework_automation_element))

as_menu_item()

Converts the element to a MenuItem.

Returns:

Type Description
MenuItem

MenuItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_menu_item(self) -> MenuItem:
    """Converts the element to a MenuItem.

    :return: MenuItem element
    """
    from FlaUI.Core.AutomationElements import MenuItem as CSMenuItem  # pyright: ignore

    return MenuItem(raw_element=CSMenuItem(self.framework_automation_element))

as_progress_bar()

Converts the element to a ProgressBar.

Returns:

Type Description
ProgressBar

ProgressBar element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_progress_bar(self) -> ProgressBar:
    """Converts the element to a ProgressBar.

    :return: ProgressBar element
    """
    from FlaUI.Core.AutomationElements import ProgressBar as CSProgressBar  # pyright: ignore

    return ProgressBar(raw_element=CSProgressBar(self.framework_automation_element))

as_radio_button()

Converts the element to a RadioButton.

Returns:

Type Description
RadioButton

RadioButton element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_radio_button(self) -> RadioButton:
    """Converts the element to a RadioButton.

    :return: RadioButton element
    """
    from FlaUI.Core.AutomationElements import RadioButton as CSRadioButton  # pyright: ignore

    return RadioButton(raw_element=CSRadioButton(self.framework_automation_element))

as_slider()

Converts the element to a Slider.

Returns:

Type Description
Slider

Slider element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_slider(self) -> Slider:
    """Converts the element to a Slider.

    :return: Slider element
    """
    from FlaUI.Core.AutomationElements import Slider as CSSlider  # pyright: ignore

    return Slider(raw_element=CSSlider(self.framework_automation_element))

as_spinner()

Converts the element to a Spinner.

Returns:

Type Description
Spinner

Spinner element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_spinner(self) -> Spinner:
    """Converts the element to a Spinner.

    :return: Spinner element
    """
    from FlaUI.Core.AutomationElements import Spinner as CSSpinner  # pyright: ignore

    return Spinner(raw_element=CSSpinner(self.framework_automation_element))

as_tab()

Converts the element to a Tab.

Returns:

Type Description
Tab

Tab element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_tab(self) -> Tab:
    """Converts the element to a Tab.

    :return: Tab element
    """
    from FlaUI.Core.AutomationElements import Tab as CSTab  # pyright: ignore

    return Tab(raw_element=CSTab(self.framework_automation_element))

as_tab_item()

Converts the element to a TabItem.

Returns:

Type Description
TabItem

TabItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_tab_item(self) -> TabItem:
    """Converts the element to a TabItem.

    :return: TabItem element
    """
    from FlaUI.Core.AutomationElements import TabItem as CSTabItem  # pyright: ignore

    return TabItem(raw_element=CSTabItem(self.framework_automation_element))

as_text_box()

Converts the element to a TextBox.

Returns:

Type Description
TextBox

TextBox element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_text_box(self) -> TextBox:
    """Converts the element to a TextBox.

    :return: TextBox element
    """
    from FlaUI.Core.AutomationElements import TextBox as CSTextBox  # pyright: ignore

    return TextBox(raw_element=CSTextBox(self.framework_automation_element))

as_thumb()

Converts the element to a Thumb.

Returns:

Type Description
Thumb

Thumb element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_thumb(self) -> Thumb:
    """Converts the element to a Thumb.

    :return: Thumb element
    """
    from FlaUI.Core.AutomationElements import Thumb as CSThumb  # pyright: ignore

    return Thumb(raw_element=CSThumb(self.framework_automation_element))

as_title_bar()

Converts the element to a TitleBar.

Returns:

Type Description
TitleBar

TitleBar element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_title_bar(self) -> TitleBar:
    """Converts the element to a TitleBar.

    :return: TitleBar element
    """
    from FlaUI.Core.AutomationElements import TitleBar as CSTitleBar  # pyright: ignore

    return TitleBar(raw_element=CSTitleBar(self.framework_automation_element))

as_toggle_button()

Converts the element to a ToggleButton.

Returns:

Type Description
ToggleButton

ToggleButton element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_toggle_button(self) -> ToggleButton:
    """Converts the element to a ToggleButton.

    :return: ToggleButton element
    """
    from FlaUI.Core.AutomationElements import ToggleButton as CSToggleButton  # pyright: ignore

    return ToggleButton(raw_element=CSToggleButton(self.framework_automation_element))

as_tree()

Converts the element to a Tree.

Returns:

Type Description
Tree

Tree element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_tree(self) -> Tree:
    """Converts the element to a Tree.

    :return: Tree element
    """
    from FlaUI.Core.AutomationElements import Tree as CSTree  # pyright: ignore

    return Tree(raw_element=CSTree(self.framework_automation_element))

as_tree_item()

Converts the element to a TreeItem.

Returns:

Type Description
TreeItem

TreeItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_tree_item(self) -> TreeItem:
    """Converts the element to a TreeItem.

    :return: TreeItem element
    """
    from FlaUI.Core.AutomationElements import TreeItem as CSTreeItem  # pyright: ignore

    return TreeItem(raw_element=CSTreeItem(self.framework_automation_element))

as_vertical_scroll_bar()

Converts the element to a VerticalScrollBar.

Returns:

Type Description
VerticalScrollBar

VerticalScrollBar element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_vertical_scroll_bar(self) -> VerticalScrollBar:
    """Converts the element to a VerticalScrollBar.

    :return: VerticalScrollBar element
    """
    from FlaUI.Core.AutomationElements.Scrolling import VerticalScrollBar as CSVerticalScrollBar  # pyright: ignore

    return VerticalScrollBar(raw_element=CSVerticalScrollBar(self.framework_automation_element))

as_window()

Converts the element to a Window.

Returns:

Type Description
Window

Window element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def as_window(self) -> Window:
    """Converts the element to a Window.

    :return: Window element
    """
    from FlaUI.Core.AutomationElements import Window as CSWindow  # pyright: ignore

    return Window(raw_element=CSWindow(self.framework_automation_element))

capture()

Captures the object as screenshot in Bitmap format.

Returns:

Type Description
Any

Captured element image Bitmap object

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def capture(self) -> Any:
    """Captures the object as screenshot in Bitmap format.

    :return: Captured element image Bitmap object
    """
    return self.raw_element.Capture()

capture_to_file(file_path)

Captures the object as screenshot directly into the given file.

Parameters:

Name Type Description Default
file_path str

The filepath where the screenshot should be saved.

required

Returns:

Type Description
None

None

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def capture_to_file(self, file_path: str) -> None:
    """Captures the object as screenshot directly into the given file.

    :param file_path: The filepath where the screenshot should be saved.
    :return: None
    """
    self.raw_element.CaptureToFile(file_path)

click(move_mouse=False, post_wait=None)

Performs a left click on the element.

Parameters:

Name Type Description Default
move_mouse bool

Flag to indicate, if the mouse should move slowly(True) or instantly(False), defaults to False

False
post_wait Optional[Union[bool, float, Callable[[], None]]]

Optional wait after operation. True=100ms, float=custom seconds, callable=custom function

None
Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def click(
    self, move_mouse: bool = False, post_wait: Optional[Union[bool, float, Callable[[], None]]] = None
) -> None:
    """Performs a left click on the element.

    :param move_mouse: Flag to indicate, if the mouse should move slowly(True) or instantly(False), defaults to False
    :param post_wait: Optional wait after operation. True=100ms, float=custom seconds, callable=custom function
    """
    from flaui.core.input import Mouse

    self.raw_element.Click(move_mouse)
    Mouse._apply_post_wait(post_wait)

double_click(move_mouse=False)

Performs a double left click on the element.

Parameters:

Name Type Description Default
move_mouse bool

Flag to indicate, if the mouse should move slowly(True) or instantly(False), defaults to False

False
Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def double_click(self, move_mouse: bool = False) -> None:
    """Performs a double left click on the element.

    :param move_mouse: Flag to indicate, if the mouse should move slowly(True) or instantly(False), defaults to False
    """
    self.raw_element.DoubleClick(move_mouse)

draw_highlight(color=Color.Red, duration=2000)

Draw a highlight around the element with the given settings.

Parameters:

Name Type Description Default
color ColorData

Color object, defaults to ColorCollection.Red

Red
duration int

Duration to highlight (in ms), defaults to 2000

2000
Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def draw_highlight(self, color: ColorData = Color.Red, duration: int = 2000) -> None:
    """Draw a highlight around the element with the given settings.

    :param color: Color object, defaults to ColorCollection.Red
    :param duration: Duration to highlight (in ms), defaults to 2000
    """
    self.raw_element.Automation.OverlayManager.Show(
        self.raw_element.Properties.BoundingRectangle.Value, color.cs_object, TypeCast.cs_timespan(duration)
    )

equals(another_element)

Compares two elements.

Parameters:

Name Type Description Default
another_element AutomationElement

Another element

required

Returns:

Type Description
bool

True/False

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def equals(self, another_element: AutomationElement) -> bool:
    """Compares two elements.

    :param another_element: Another element
    :return: True/False
    """
    return self.raw_element.Equals(another_element.raw_element)

find_all(tree_scope, condition)

Finds all children with the condition.

:aram tree_scope: Treescope object

Parameters:

Name Type Description Default
condition PropertyCondition

The search condition.

required

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all(self, tree_scope: TreeScope, condition: PropertyCondition) -> AutomationElementCollection:
    """Finds all children with the condition.

    :aram tree_scope: Treescope object
    :param condition: The search condition.
    :return: The found elements or an empty collection if no elements were found.
    """
    return AutomationElementCollection(
        AutomationElement(raw_element=_) for _ in self.raw_element.FindAll(tree_scope.value, condition.cs_condition)
    )

find_all_by_x_path(x_path)

Finds all items which match the given xpath.

Parameters:

Name Type Description Default
x_path str

Element XPath

required

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all_by_x_path(self, x_path: str) -> AutomationElementCollection:
    """Finds all items which match the given xpath.

    :param x_path: Element XPath
    :return: The found elements or an empty collection if no elements were found.
    """
    return AutomationElementCollection(
        AutomationElement(raw_element=_) for _ in self.raw_element.FindAllByXPath(x_path)
    )

find_all_children(condition=None)

Finds all children with the condition.

Parameters:

Name Type Description Default
condition Optional[PropertyCondition]

The search condition.

None

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all_children(self, condition: Optional[PropertyCondition] = None) -> AutomationElementCollection:
    """Finds all children with the condition.

    :param condition: The search condition.
    :return: The found elements or an empty collection if no elements were found.
    """
    if condition is None:
        return AutomationElementCollection(
            AutomationElement(raw_element=_) for _ in self.raw_element.FindAllChildren()
        )
    return AutomationElementCollection(
        AutomationElement(raw_element=_) for _ in self.raw_element.FindAllChildren(condition.cs_condition)
    )

find_all_descendants(condition=None)

Finds all descendants with the condition.

Parameters:

Name Type Description Default
condition Optional[PropertyCondition]

The search condition.

None

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all_descendants(self, condition: Optional[PropertyCondition] = None) -> AutomationElementCollection:
    """Finds all descendants with the condition.

    :param condition: The search condition.
    :return: The found elements or an empty collection if no elements were found.
    """
    if condition is None:
        return AutomationElementCollection(
            AutomationElement(raw_element=_) for _ in self.raw_element.FindAllDescendants()
        )
    return AutomationElementCollection(
        AutomationElement(raw_element=_) for _ in self.raw_element.FindAllDescendants(condition.cs_condition)
    )

find_all_nested(condition)

Finds all elements by iterating thru all conditions.

Parameters:

Name Type Description Default
condition PropertyCondition

The search condition.

required

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all_nested(self, condition: PropertyCondition) -> AutomationElementCollection:
    """Finds all elements by iterating thru all conditions.

    :param condition: The search condition.
    :return: The found elements or an empty collection if no elements were found.
    """
    return AutomationElementCollection(
        AutomationElement(raw_element=_) for _ in self.raw_element.FindAllNested(condition.cs_condition)
    )

find_all_with_options(tree_scope, condition, traversal_options, root)

Find all matching elements in the specified order.

Parameters:

Name Type Description Default
tree_scope TreeScope

A combination of values specifying the scope of the search.

required
condition PropertyCondition

A condition that represents the criteria to match.

required
traversal_options TreeTraversalOptions

Value specifying the tree navigation order.

required
root AutomationElement

An element with which to begin the search.

required

Returns:

Type Description
AutomationElementCollection

The found elements or an empty collection if no elements were found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_all_with_options(
    self,
    tree_scope: TreeScope,
    condition: PropertyCondition,
    traversal_options: TreeTraversalOptions,
    root: AutomationElement,
) -> AutomationElementCollection:
    """Find all matching elements in the specified order.

    :param tree_scope: A combination of values specifying the scope of the search.
    :param condition: A condition that represents the criteria to match.
    :param traversal_options: Value specifying the tree navigation order.
    :param root: An element with which to begin the search.
    :return: The found elements or an empty collection if no elements were found.
    """
    return AutomationElementCollection(
        AutomationElement(raw_element=_)
        for _ in self.raw_element.FindAllWithOptions(
            tree_scope.value, condition.cs_condition, traversal_options.value, root.raw_element
        )
    )

find_at(tree_scope, index, condition)

Finds the element with the given index with the given condition.

Parameters:

Name Type Description Default
tree_scope TreeScope

The scope to search.

required
index int

The index of the element to return (0-based).

required
condition PropertyCondition

The condition to use.

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_at(self, tree_scope: TreeScope, index: int, condition: PropertyCondition) -> AutomationElement:
    """Finds the element with the given index with the given condition.

    :param tree_scope: The scope to search.
    :param index: The index of the element to return (0-based).
    :param condition: The condition to use.
    :return: The found element or null if no element was found.
    """
    return AutomationElement(raw_element=self.raw_element.FindAt(tree_scope.value, index, condition.cs_condition))

find_child_at(index, condition)

Finds the child at the given position with the condition.

Parameters:

Name Type Description Default
index int

The index of the child to find.

required
condition PropertyCondition

The condition.

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_child_at(self, index: int, condition: PropertyCondition) -> AutomationElement:
    """Finds the child at the given position with the condition.

    :param index: The index of the child to find.
    :param condition: The condition.
    :return: The found element or null if no element was found.
    """
    return AutomationElement(raw_element=self.raw_element.FindChildAt(index, condition.cs_condition))

find_first(tree_scope, condition)

Finds the first element in the given scope with the given condition.

Parameters:

Name Type Description Default
tree_scope TreeScope

The scope to search.

required
condition PropertyCondition

The condition to use.

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first(self, tree_scope: TreeScope, condition: PropertyCondition) -> AutomationElement:
    """Finds the first element in the given scope with the given condition.

    :param tree_scope: The scope to search.
    :param condition: The condition to use.
    :return: The found element or null if no element was found.
    """
    return AutomationElement(raw_element=self.raw_element.FindFirst(tree_scope.value, condition.cs_condition))

find_first_by_x_path(x_path)

Finds for the first item which matches the given xpath.

Parameters:

Name Type Description Default
x_path str

XPath to the element

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first_by_x_path(self, x_path: str) -> AutomationElement:
    """Finds for the first item which matches the given xpath.

    :param x_path: XPath to the element
    :return: The found element or null if no element was found.
    """
    return AutomationElement(raw_element=self.raw_element.FindFirstByXPath(x_path))

find_first_child(condition=None)

Finds the first child.

Parameters:

Name Type Description Default
condition Optional[PropertyCondition]

The condition to use.

None

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first_child(self, condition: Optional[PropertyCondition] = None) -> AutomationElement:
    """Finds the first child.

    :param condition: The condition to use.
    :return: The found element or null if no element was found.
    """
    if condition is None:
        return AutomationElement(raw_element=self.raw_element.FindFirstChild())
    else:
        return AutomationElement(raw_element=self.raw_element.FindFirstChild(condition.cs_condition))

find_first_descendant(condition=None)

Finds the first descendant.

Parameters:

Name Type Description Default
condition Optional[PropertyCondition]

The condition to use.

None

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first_descendant(self, condition: Optional[PropertyCondition] = None) -> AutomationElement:
    """Finds the first descendant.

    :param condition: The condition to use.
    :return: The found element or null if no element was found.
    """
    if condition is None:
        return AutomationElement(raw_element=self.raw_element.FindFirstDescendant())
    else:
        return AutomationElement(raw_element=self.raw_element.FindFirstDescendant(condition.cs_condition))

find_first_nested(conditions)

Finds the first element by iterating thru all conditions.

C# signature: FindFirstNested(params ConditionBase[] nestedConditions) Iterates through children using each condition in sequence.

Parameters:

Name Type Description Default
conditions Union[PropertyCondition, List[PropertyCondition]]

Single condition or list of conditions to iterate through.

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first_nested(self, conditions: Union[PropertyCondition, List[PropertyCondition]]) -> AutomationElement:
    """Finds the first element by iterating thru all conditions.

    C# signature: FindFirstNested(params ConditionBase[] nestedConditions)
    Iterates through children using each condition in sequence.

    :param conditions: Single condition or list of conditions to iterate through.
    :return: The found element or null if no element was found.
    """
    if isinstance(conditions, list):
        # Convert list to C# params array
        from FlaUI.Core.Conditions import ConditionBase  # pyright: ignore[reportMissingImports]
        from System import Array  # pyright: ignore[reportMissingImports]

        cs_conditions = Array[ConditionBase]([c.cs_condition for c in conditions])
        return AutomationElement(raw_element=self.raw_element.FindFirstNested(cs_conditions))
    else:
        return AutomationElement(raw_element=self.raw_element.FindFirstNested(conditions.cs_condition))

find_first_with_options(tree_scope, condition, traversal_options, root)

Find first matching element in the specified order.

Parameters:

Name Type Description Default
tree_scope TreeScope

A combination of values specifying the scope of the search.

required
condition PropertyCondition

A condition that represents the criteria to match.

required
traversal_options TreeTraversalOptions

Value specifying the tree navigation order.

required
root Any

An element with which to begin the search.

required

Returns:

Type Description
AutomationElement

The found element or null if no element was found.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def find_first_with_options(
    self, tree_scope: TreeScope, condition: PropertyCondition, traversal_options: TreeTraversalOptions, root: Any
) -> AutomationElement:
    """Find first matching element in the specified order.

    :param tree_scope: A combination of values specifying the scope of the search.
    :param condition: A condition that represents the criteria to match.
    :param traversal_options: Value specifying the tree navigation order.
    :param root: An element with which to begin the search.
    :return: The found element or null if no element was found.
    """
    return AutomationElement(
        raw_element=self.raw_element.FindFirstWithOptions(
            tree_scope.value, condition.cs_condition, traversal_options.value, root.raw_element
        )
    )

focus()

Sets the focus to a control. If the control is a window, brings it to the foreground

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def focus(self) -> None:
    """Sets the focus to a control. If the control is a window, brings it to the foreground"""
    self.raw_element.Focus()

focus_native()

Sets the focus by using the Win32 SetFocus() method

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def focus_native(self) -> None:
    """Sets the focus by using the Win32 SetFocus() method"""
    self.raw_element.FocusNative()

get_clickable_point()

Gets a clickable point of the element.

Returns:

Type Description
Point

Clickable point object

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_clickable_point(self) -> Point:
    """Gets a clickable point of the element.

    :return: Clickable point object
    """
    return Point(raw_value=self.raw_element.GetClickablePoint())

get_current_metadata_value(property_id, meta_data_id)

Gets metadata from the UI Automation element that indicates how the information should be interpreted.

Parameters:

Name Type Description Default
property_id Any

The property to retrieve.

required
meta_data_id int

Specifies the type of metadata to retrieve.

required

Returns:

Type Description
Any

The metadata.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_current_metadata_value(self, property_id: Any, meta_data_id: int) -> Any:
    """Gets metadata from the UI Automation element that indicates how the information should be interpreted.

    :param property_id: The property to retrieve.
    :param meta_data_id: Specifies the type of metadata to retrieve.
    :return: The metadata.
    """
    return self.raw_element.GetCurrentMetadataValue(property_id, meta_data_id)

get_hash_code()

Fetches the hash code of the current element

Returns:

Type Description
int

Hash code

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_hash_code(self) -> int:
    """Fetches the hash code of the current element

    :return: Hash code
    """
    return self.raw_element.GetHashCode()

get_supported_patterns()

Gets the available patterns for an element via properties.

Returns:

Type Description
Any

Available patterns for an element via properties.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_supported_patterns(self) -> Any:
    """Gets the available patterns for an element via properties.

    :return: Available patterns for an element via properties.
    """
    return TypeCast.py_list(self.raw_element.GetSupportedPatterns())

get_supported_patterns_direct()

Gets the available patterns for an element via UIA method. Does not work with cached elements and might be unreliable.

Returns:

Type Description
Any

Available patterns

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_supported_patterns_direct(self) -> Any:
    """Gets the available patterns for an element via UIA method. Does not work with cached elements and might be unreliable.

    :return: Available patterns
    """
    return TypeCast.py_list(self.raw_element.GetSupportedPatternsDirect())

get_supported_properties_direct()

Gets the available properties for an element via UIA method. Does not work with cached elements and might be unreliable.

Returns:

Type Description
Any

Available properties

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_supported_properties_direct(self) -> Any:
    """Gets the available properties for an element via UIA method. Does not work with cached elements and might be unreliable.

    :return: Available properties
    """
    return TypeCast.py_list(self.raw_element.GetSupportedPropertiesDirect())

get_x_path_navigator()

Return an XPath navigator rooted at this element for manual UIA-tree navigation.

For most use cases prefer :meth:find_first_by_x_path / :meth:find_all_by_x_path; this exposes the underlying navigator for advanced traversal.

Returns:

Type Description
'AutomationElementXPathNavigator'

An :class:~flaui.core.xpath_navigator.AutomationElementXPathNavigator.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_x_path_navigator(self) -> "AutomationElementXPathNavigator":
    """Return an XPath navigator rooted at this element for manual UIA-tree navigation.

    For most use cases prefer :meth:`find_first_by_x_path` / :meth:`find_all_by_x_path`; this
    exposes the underlying navigator for advanced traversal.

    :return: An :class:`~flaui.core.xpath_navigator.AutomationElementXPathNavigator`.
    """
    from flaui.core.xpath_navigator import AutomationElementXPathNavigator

    return AutomationElementXPathNavigator.from_element(self)

is_pattern_supported(pattern_id)

Checks if the given pattern is available for the element via properties.

Parameters:

Name Type Description Default
pattern_id Any

Pattern

required

Returns:

Type Description
bool

True if supported else False

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def is_pattern_supported(self, pattern_id: Any) -> bool:
    """Checks if the given pattern is available for the element via properties.

    :param pattern_id: Pattern
    :return: True if supported else False
    """
    return self.raw_element.IsPatternSupported(pattern_id)

is_pattern_supported_direct(pattern_id)

Checks if the given pattern is available for the element via UIA method. Does not work with cached elements and might be unreliable.

Parameters:

Name Type Description Default
pattern_id Any

Pattern ID

required

Returns:

Type Description
bool

True if supported else False

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def is_pattern_supported_direct(self, pattern_id: Any) -> bool:
    """Checks if the given pattern is available for the element via UIA method. Does not work with cached elements and might be unreliable.

    :param pattern_id: Pattern ID
    :return: True if supported else False
    """
    return self.raw_element.IsPatternSupportedDirect(pattern_id)

is_property_supported_direct(property)

Method to check if the element supports the given property via UIA method. Does not work with cached elements and might be unreliable.

Parameters:

Name Type Description Default
property Any

Property to check

required

Returns:

Type Description
bool

True if supported else False

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def is_property_supported_direct(self, property: Any) -> bool:
    """Method to check if the element supports the given property via UIA method. Does not work with cached elements and might be unreliable.

    :param property: Property to check
    :return: True if supported else False
    """
    return self.raw_element.IsPropertySupportedDirect(property)

register_active_text_position_changed_event(tree_scope, action)

Register an active-text-position-changed event handler.

Parameters:

Name Type Description Default
tree_scope TreeScope

The tree scope to listen on.

required
action Callable[['AutomationElement', Any], None]

Callback (element, text_range) -> None invoked when the event fires.

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_active_text_position_changed_event(
    self, tree_scope: TreeScope, action: Callable[["AutomationElement", Any], None]
) -> "EventRegistration":
    """Register an active-text-position-changed event handler.

    :param tree_scope: The tree scope to listen on.
    :param action: Callback ``(element, text_range) -> None`` invoked when the event fires.
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_tree_scope,
        make_active_text_position_delegate,
        safe_invoke,
    )
    from flaui.core.text_range import TextRange

    def _handler(sender: Any, text_range: Any) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), TextRange(raw_text_range=text_range))

    handler = self.raw_element.RegisterActiveTextPositionChangedEvent(
        coerce_tree_scope(tree_scope), make_active_text_position_delegate(_handler)
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterActiveTextPositionChangedEventHandler(h),
    )

register_automation_event(event, tree_scope, action)

Register an automation event handler.

Parameters:

Name Type Description Default
event Any

The event to listen for (an EventId wrapper or a raw C# EventId).

required
tree_scope TreeScope

The tree scope to listen on.

required
action Callable[['AutomationElement', Any], None]

Callback (element, event_id) -> None invoked when the event fires.

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_automation_event(
    self, event: Any, tree_scope: TreeScope, action: Callable[["AutomationElement", Any], None]
) -> "EventRegistration":
    """Register an automation event handler.

    :param event: The event to listen for (an ``EventId`` wrapper or a raw C# ``EventId``).
    :param tree_scope: The tree scope to listen on.
    :param action: Callback ``(element, event_id) -> None`` invoked when the event fires.
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_event_id,
        coerce_tree_scope,
        make_automation_event_delegate,
        safe_invoke,
    )

    def _handler(sender: Any, event_id: Any) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), event_id)

    handler = self.raw_element.RegisterAutomationEvent(
        coerce_event_id(event), coerce_tree_scope(tree_scope), make_automation_event_delegate(_handler)
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterAutomationEventHandler(h),
    )

register_notification_event(tree_scope, action)

Register a notification event handler.

Parameters:

Name Type Description Default
tree_scope TreeScope

The tree scope to listen on.

required
action Callable[['AutomationElement', Any, Any, str, str], None]

Callback (element, notification_kind, notification_processing, display_string, activity_id) -> None invoked when the event fires.

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_notification_event(
    self, tree_scope: TreeScope, action: Callable[["AutomationElement", Any, Any, str, str], None]
) -> "EventRegistration":
    """Register a notification event handler.

    :param tree_scope: The tree scope to listen on.
    :param action: Callback ``(element, notification_kind, notification_processing, display_string,
        activity_id) -> None`` invoked when the event fires.
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_tree_scope,
        make_notification_delegate,
        safe_invoke,
    )

    def _handler(sender: Any, kind: Any, processing: Any, display_string: str, activity_id: str) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), kind, processing, display_string, activity_id)

    handler = self.raw_element.RegisterNotificationEvent(
        coerce_tree_scope(tree_scope), make_notification_delegate(_handler)
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterNotificationEventHandler(h),
    )

register_property_changed_event(tree_scope, action, properties)

Register a property-changed event handler for the given properties.

Parameters:

Name Type Description Default
tree_scope TreeScope

The tree scope to listen on.

required
action Callable[['AutomationElement', Any, Any], None]

Callback (element, property_id, new_value) -> None invoked on change.

required
properties List[Any]

Properties to watch (PropertyId wrappers or raw C# PropertyId).

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_property_changed_event(
    self,
    tree_scope: TreeScope,
    action: Callable[["AutomationElement", Any, Any], None],
    properties: List[Any],
) -> "EventRegistration":
    """Register a property-changed event handler for the given properties.

    :param tree_scope: The tree scope to listen on.
    :param action: Callback ``(element, property_id, new_value) -> None`` invoked on change.
    :param properties: Properties to watch (``PropertyId`` wrappers or raw C# ``PropertyId``).
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from System import Array  # pyright: ignore

    from FlaUI.Core.Identifiers import PropertyId as CSPropertyId  # pyright: ignore

    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_property_id,
        coerce_tree_scope,
        make_property_changed_delegate,
        safe_invoke,
    )

    def _handler(sender: Any, property_id: Any, new_value: Any) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), property_id, new_value)

    raw_properties = Array[CSPropertyId]([coerce_property_id(_) for _ in properties])
    handler = self.raw_element.RegisterPropertyChangedEvent(
        coerce_tree_scope(tree_scope), make_property_changed_delegate(_handler), raw_properties
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterPropertyChangedEventHandler(h),
    )

register_structure_changed_event(tree_scope, action)

Register a structure-changed event handler.

Parameters:

Name Type Description Default
tree_scope TreeScope

The tree scope to listen on.

required
action Callable[['AutomationElement', Any, List[int]], None]

Callback (element, change_type, runtime_id) -> None invoked on change.

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_structure_changed_event(
    self, tree_scope: TreeScope, action: Callable[["AutomationElement", Any, List[int]], None]
) -> "EventRegistration":
    """Register a structure-changed event handler.

    :param tree_scope: The tree scope to listen on.
    :param action: Callback ``(element, change_type, runtime_id) -> None`` invoked on change.
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_tree_scope,
        make_structure_changed_delegate,
        safe_invoke,
    )

    def _handler(sender: Any, change_type: Any, runtime_id: Any) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), change_type, runtime_id)

    handler = self.raw_element.RegisterStructureChangedEvent(
        coerce_tree_scope(tree_scope), make_structure_changed_delegate(_handler)
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterStructureChangedEventHandler(h),
    )

register_text_edit_text_changed_event_handler(tree_scope, text_edit_change_type, action)

Register a text-edit text-changed event handler.

Parameters:

Name Type Description Default
tree_scope TreeScope

The tree scope to listen on.

required
text_edit_change_type Any

The C# TextEditChangeType to listen for.

required
action Callable[['AutomationElement', Any, List[str]], None]

Callback (element, change_type, event_strings) -> None invoked on change.

required

Returns:

Type Description
'EventRegistration'

An :class:~flaui.core.event_handlers.EventRegistration handle.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def register_text_edit_text_changed_event_handler(
    self,
    tree_scope: TreeScope,
    text_edit_change_type: Any,
    action: Callable[["AutomationElement", Any, List[str]], None],
) -> "EventRegistration":
    """Register a text-edit text-changed event handler.

    :param tree_scope: The tree scope to listen on.
    :param text_edit_change_type: The C# ``TextEditChangeType`` to listen for.
    :param action: Callback ``(element, change_type, event_strings) -> None`` invoked on change.
    :return: An :class:`~flaui.core.event_handlers.EventRegistration` handle.
    """
    from flaui.core.event_handlers import (
        EventRegistration,
        coerce_tree_scope,
        make_text_edit_delegate,
        safe_invoke,
    )

    def _handler(sender: Any, change_type: Any, event_strings: Any) -> None:
        """Bridge the C# callback to the Python action."""
        safe_invoke(action, AutomationElement(raw_element=sender), change_type, event_strings)

    handler = self.raw_element.RegisterTextEditTextChangedEventHandler(
        coerce_tree_scope(tree_scope),
        getattr(text_edit_change_type, "value", text_edit_change_type),
        make_text_edit_delegate(_handler),
    )
    return EventRegistration(
        cs_handler=handler,
        callback=_handler,
        unregister=lambda h: self.framework_automation_element.UnregisterTextEditTextChangedEventHandler(h),
    )

right_click(move_mouse=False)

Performs a right click on the element.

Parameters:

Name Type Description Default
move_mouse bool

Flag to indicate, if the mouse should move slowly (true) or instantly (false)., defaults to False

False
Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def right_click(self, move_mouse: bool = False) -> None:
    """Performs a right click on the element.

    :param move_mouse: Flag to indicate, if the mouse should move slowly (true) or instantly (false)., defaults to False
    """
    self.raw_element.RightClick(move_mouse)

right_double_click(move_mouse=False)

Performs a double right click on the element.

Parameters:

Name Type Description Default
move_mouse bool

Flag to indicate, if the mouse should move slowly (true) or instantly (false)., defaults to False

False
Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def right_double_click(self, move_mouse: bool = False) -> None:
    """Performs a double right click on the element.

    :param move_mouse: Flag to indicate, if the mouse should move slowly (true) or instantly (false)., defaults to False
    """
    self.raw_element.RightDoubleClick(move_mouse)

set_focus()

Sets the focus to a control. If the control is a window, brings it to the foreground

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def set_focus(self) -> None:
    """Sets the focus to a control. If the control is a window, brings it to the foreground"""
    self.raw_element.SetFocus()

set_foreground()

Brings a window to the foreground

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def set_foreground(self) -> None:
    """Brings a window to the foreground"""
    self.raw_element.SetForeground()

to_string()

Overrides the string representation of the element with something useful.

Returns:

Type Description
str

String object

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def to_string(self) -> str:
    """Overrides the string representation of the element with something useful.

    :return: String object
    """
    return self.raw_element.ToString()

try_get_clickable_point()

Tries to get a clickable point of the element.

Returns:

Type Description
Tuple[bool, Point]

Tuple[flag, Point] - True if a point was found, false otherwise; The clickable point or null, if no point was found

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def try_get_clickable_point(self) -> Tuple[bool, Point]:
    """Tries to get a clickable point of the element.

    :return: Tuple[flag, Point] - True if a point was found, false otherwise; The clickable point or null, if no point was found
    """
    flag, point = self.raw_element.TryGetClickablePoint()
    return (flag, Point(raw_value=point))