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 onselected_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, orItemRealizer.realize_items(list_box)to realise them all, before searching. selecttakes an index or the item text.select(0)andselect("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
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
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
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 |