Skip to content

ComboBox

WinForms combo boxes don't work through UI Automation

On WinForms, with both UIA2 and UIA3, items comes back empty, select(index) raises IndexOutOfRangeException, and expand() leaves the box collapsed. The bug is in Windows/.NET, not in FlaUI or this wrapper, and upstream FlaUI skips its WinForms combo box tests for the same reason (#75). WPF combo boxes work normally.

Usage notes

  • Bring the window to the front first. A WPF drop-down closes as soon as its window loses focus, for example when another window overlaps it. Call set_foreground() on the window before expand().
  • Wait for the state, not a fixed sleep. The drop-down animates open. Poll expand_collapse_state with Retry.While until it reports ExpandCollapseState.Expanded.
  • Editable combo boxes take text through editable_text; setting it selects the matching item.

flaui.core.automation_elements.ComboBox

Bases: AutomationElement

Class to interact with a combobox element

animation_duration property writable

Timespan to wait until the animation for opening/closing is finished.

Returns:

Type Description
Any

C# TimeSpan object from System namespace

editable_text property writable

The text of the editable element inside the combobox. Only works if the combobox is editable.

Returns:

Type Description
str

Editable text of the element

expand_collapse_state property

Gets the ExpandCollapseStateof the element

Returns:

Type Description
ExpandCollapseState

Expand/Collapse state

is_editable property

Flag which indicates, if the combobox is editable or not

Returns:

Type Description
bool

True If element editable, else False

is_read_only property

Flag which indicates, if the combobox is read-only or not

Returns:

Type Description
bool

True If element read-only, else False

items property

Gets all available items from the ComboBox element

Returns:

Type Description
List[ComboBoxItem]

Item

selected_item property

Gets the first selected item or null otherwise

Returns:

Type Description
ComboBoxItem

Selected item

selected_items property

Gets all selected items

Returns:

Type Description
List[str]

Selected items

value property

Selected value of the Combobox element

Returns:

Type Description
str

Element selected value

collapse()

Collapses the element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def collapse(self) -> None:
    """Collapses the element"""
    self.raw_element.Collapse()

expand()

Expands the element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def expand(self) -> None:
    """Expands the element"""
    self.raw_element.Expand()

select(value)

Select an item by index/the first item which matches the given text..

Parameters:

Name Type Description Default
value Union[int, str]

Index value/The text to search for

required

Returns:

Type Description
ComboBoxItem

The first found item or null if no item matches.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def select(self, value: Union[int, str]) -> ComboBoxItem:
    """Select an item by index/the first item which matches the given text..

    :param value: Index value/The text to search for
    :return: The first found item or null if no item matches.
    """
    return ComboBoxItem(raw_element=self.raw_element.Select(value))