Skip to content

ListBox

Usage notes

  • Selection persists. A list box keeps its selection across tests while the app stays open. If your tests share one app instance, clear any leftover selection with remove_from_selection(...) before asserting on selected_items (#83).
  • WinForms single-select lists can't be emptied. Once an item is selected, removing it raises "Selection container requires one selection". Select the item you need instead of clearing first.
  • Large WPF lists are virtualised. Items that are off screen don't exist in the automation tree yet. Call scroll_into_view() on an item, or ItemRealizer.realize_items(list_box) to realise them all, before searching.
  • select takes an index or the item text. select(0) and select("Item 1") call FlaUI's matching overloads directly.

flaui.core.automation_elements.ListBox

Bases: AutomationElement

Class to interact with a list box element

items property

Returns all the list box items

Returns:

Type Description
List[ListBoxItem]

List of ListBoxItem elements

selected_item property

Gets the first selected item or null otherwise.

Returns:

Type Description
ListBoxItem

ListBoxItem element if selected, else None

selected_items property

Gets all selected items.

Returns:

Type Description
List[ListBoxItem]

List of ListBoxItem elements

add_to_selection(value)

Add a row to the selection by index/by text.

Parameters:

Name Type Description Default
value Union[str, int]

Text/Index

required

Returns:

Type Description
ListBoxItem

ListBoxItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def add_to_selection(self, value: Union[str, int]) -> ListBoxItem:
    """Add a row to the selection by index/by text.

    :param value: Text/Index
    :return: ListBoxItem element
    """
    return ListBoxItem(raw_element=self.raw_element.AddToSelection(value))

remove_from_selection(value)

Remove a row to the selection by index/by text.

Parameters:

Name Type Description Default
value Union[str, int]

Text/Index

required

Returns:

Type Description
ListBoxItem

ListBoxItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def remove_from_selection(self, value: Union[str, int]) -> ListBoxItem:
    """Remove a row to the selection by index/by text.

    :param value: Text/Index
    :return: ListBoxItem element
    """
    return ListBoxItem(raw_element=self.raw_element.RemoveFromSelection(value))

select(value)

Selects an item by index or text.

Parameters:

Name Type Description Default
value Union[str, int]

Text to select/Index to select by

required

Returns:

Type Description
ListBoxItem

ListBoxItem element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def select(self, value: Union[str, int]) -> ListBoxItem:
    """Selects an item by index or text.

    :param value: Text to select/Index to select by
    :return: ListBoxItem element
    """
    return ListBoxItem(raw_element=self.raw_element.Select(value))