VirtualListElement
Playwright element wrapper for <vaadin-virtual-list> providing a virtualized scrollable list that lazily renders items as the user scrolls.
Component Tag
vaadin-virtual-list
Implements
FocusableElement - Focus management
HasStyleElement - CSS class and style management
Constructor
Playwright locator for the <vaadin-virtual-list> element
Static Factory Methods
get
Get the first virtual list on the page.
VirtualListElement.get(Page page)
Property Methods
getRowCount
Get the total number of items in the list.
Returns total item count (including items not yet rendered).
getFirstVisibleRowIndex
Get the index of the first row that is at least partially visible.
int getFirstVisibleRowIndex()
Returns 0-based index of the first visible row.
getLastVisibleRowIndex
Get the index of the last row that is at least partially visible.
int getLastVisibleRowIndex()
Returns 0-based index of the last visible row.
getVisibleRowCount
Get the number of currently visible rows.
Returns count of rows visible in the viewport.
isRowInView
Whether the given row index is currently visible in the viewport.
boolean isRowInView(int rowIndex)
0-based row index to check
Item Query Methods
getRenderedItems
Get a locator matching all currently rendered child elements.
Locator getRenderedItems()
getItemByIndex
Get the rendered DOM element at the given virtual index.
Locator getItemByIndex(int index)
0-based virtual row index (must be currently in view)
getItemByText
Get a rendered item containing the given text.
Locator getItemByText(String text)
Component Query Methods
getItemComponent
Get a typed component element from the rendered item at the given virtual index.
<T extends VaadinElement> T getItemComponent(int index, Class<T> type)
0-based virtual row index (must be in view)
Element class (e.g., ButtonElement.class)
getItemComponentByText
Get a typed component element from the rendered item whose text matches.
<T extends VaadinElement> T getItemComponentByText(String text, Class<T> type)
Text used to locate the item
Element class (e.g., ButtonElement.class)
getComponent
Get the first typed component element found anywhere in the currently rendered items.
<T extends VaadinElement> T getComponent(Class<T> type)
Element class (e.g., ButtonElement.class)
Scroll the list so the given row index becomes visible.
void scrollToRow(int rowIndex)
Scroll to the very beginning of the list.
Scroll to the very end of the list.
Assertion Methods
assertRowCount
Assert the total number of items matches the expected count.
void assertRowCount(int expected)
assertRowInView
Assert that the given row index is currently visible.
void assertRowInView(int rowIndex)
assertRowNotInView
Assert that the given row index is NOT currently visible.
void assertRowNotInView(int rowIndex)
assertFirstVisibleRow
Assert that the first visible row index equals the expected value.
void assertFirstVisibleRow(int expected)
Expected first visible row index
assertLastVisibleRow
Assert that the last visible row index equals the expected value.
void assertLastVisibleRow(int expected)
Expected last visible row index
assertItemRendered
Assert that an item containing the given text is currently rendered.
void assertItemRendered(String text)
assertEmpty
Assert the list has zero items.
Usage Examples
Basic Virtual List Operations
VirtualListElement virtualList = VirtualListElement.get(page);
int totalRows = virtualList.getRowCount();
assertEquals(1000, totalRows);
int visibleRows = virtualList.getVisibleRowCount();
assertTrue(visibleRows < totalRows);
VirtualListElement virtualList = VirtualListElement.get(page);
virtualList.scrollToRow(500);
virtualList.assertRowInView(500);
int firstVisible = virtualList.getFirstVisibleRowIndex();
int lastVisible = virtualList.getLastVisibleRowIndex();
assertTrue(firstVisible <= 500 && 500 <= lastVisible);
Access Item Content
VirtualListElement virtualList = VirtualListElement.get(page);
// Get item by index
Locator item = virtualList.getItemByIndex(10);
assertThat(item).isVisible();
// Get item by text
Locator itemByText = virtualList.getItemByText("Item 42");
assertThat(itemByText).hasText("Item 42");
Work with Components in Items
VirtualListElement virtualList = VirtualListElement.get(page);
// Get button from item at index 5
ButtonElement button = virtualList.getItemComponent(5, ButtonElement.class);
button.click();
// Get first button in any rendered item
ButtonElement anyButton = virtualList.getComponent(ButtonElement.class);
assertThat(anyButton.getLocator()).isVisible();
VirtualListElement virtualList = VirtualListElement.get(page);
// Scroll to start
virtualList.scrollToStart();
virtualList.assertFirstVisibleRow(0);
// Scroll to end
virtualList.scrollToEnd();
int lastRow = virtualList.getRowCount() - 1;
virtualList.assertRowInView(lastRow);
Assert List State
VirtualListElement virtualList = VirtualListElement.get(page);
virtualList.assertRowCount(1000);
virtualList.assertItemRendered("Item 1");
// Empty list
VirtualListElement emptyList = VirtualListElement.get(page);
emptyList.assertEmpty();
Check Rendered Items
VirtualListElement virtualList = VirtualListElement.get(page);
Locator allRendered = virtualList.getRenderedItems();
int renderedCount = allRendered.count();
assertTrue(renderedCount > 0);
assertTrue(renderedCount < virtualList.getRowCount());