ListBoxElement
Playwright element wrapper for <vaadin-list-box> supporting single and multiple selection, item-level enablement, and label-based lookup.
Component Tag
vaadin-list-box
vaadin-item - List box item element
Implements
HasAriaLabelElement - ARIA label support
HasStyleElement - CSS class and style management
HasTooltipElement - Tooltip text
HasEnabledElement - Enable/disable state
Constructor
Playwright locator for the <vaadin-list-box> element
Static Factory Methods
getByLabel
Get a list box by its accessible label.
ListBoxElement.getByLabel(Page page, String label)
List box’s accessible label (ARIA role: LISTBOX)
Methods
selectItem
Select an item based on its text. In multiple mode, toggles selection state.
void selectItem(String item)
Visible label of the item
getSingleSelectedValue
Get the selected value for single-select list boxes.
String getSingleSelectedValue()
Returns the text content of the selected item.
getSelectedValue
Get all selected values for multi-select list boxes.
List<String> getSelectedValue()
Returns a list of text contents for all selected items.
isMultiple
Whether the list box is in multiple selection mode.
Assertion Methods
assertSelectedValue
Assert that the selected values match the expected labels.
void assertSelectedValue(String... expected)
Expected selected item labels
assertItemEnabled
Assert that a specific item is enabled.
void assertItemEnabled(String item)
assertItemDisabled
Assert that a specific item is disabled.
void assertItemDisabled(String item)
assertMultiple
Assert that multiple selection is enabled.
assertSingle
Assert that single selection mode is enabled.
Usage Examples
Basic Selection
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Sort by");
listBox.assertVisible();
listBox.assertSelectedValue("Most recent first");
listBox.selectItem("Rating: high to low");
listBox.assertSelectedValue("Rating: high to low");
Single Selection Mode
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Sort options");
listBox.assertSingle();
// Clicking same item doesn't unselect in single mode
listBox.selectItem("Rating: high to low");
listBox.selectItem("Rating: high to low");
listBox.assertSelectedValue("Rating: high to low");
Multiple Selection Mode
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Multiple list");
listBox.assertMultiple();
listBox.assertSelectedValue("Most recent first");
// Add to selection
listBox.selectItem("Rating: high to low");
listBox.assertSelectedValue("Most recent first", "Rating: high to low");
// Toggle off
listBox.selectItem("Rating: high to low");
listBox.assertSelectedValue("Most recent first");
// Unselect all
listBox.selectItem("Most recent first");
listBox.assertSelectedValue();
Check Item State
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Enabled/Disabled Field");
listBox.assertDisabled();
listBox.assertItemDisabled("Most recent first");
listBox.assertItemDisabled("Always disabled");
page.locator("#enable-button").click();
listBox.assertEnabled();
listBox.assertItemEnabled("Most recent first");
listBox.assertItemDisabled("Always disabled"); // Still disabled
ARIA Label
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Invisible label");
listBox.assertAriaLabel("Invisible label");
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Sort by");
listBox.assertTooltipHasText("Tooltip for listbox");
CSS Class
ListBoxElement listBox = ListBoxElement.getByLabel(page, "Options");
listBox.assertCssClass("list-box");