Skip to main content

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

locator
Locator
required
Playwright locator for the <vaadin-virtual-list> element

Static Factory Methods

get

Get the first virtual list on the page.
VirtualListElement.get(Page page)
page
Page
Playwright page

Property Methods

getRowCount

Get the total number of items in the list.
int getRowCount()
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.
int getVisibleRowCount()
Returns count of rows visible in the viewport.

isRowInView

Whether the given row index is currently visible in the viewport.
boolean isRowInView(int rowIndex)
rowIndex
int
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)
index
int
0-based virtual row index (must be currently in view)

getItemByText

Get a rendered item containing the given text.
Locator getItemByText(String text)
text
String
Text to search for

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)
index
int
0-based virtual row index (must be in view)
type
Class<T>
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
String
Text used to locate the item
type
Class<T>
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)
type
Class<T>
Element class (e.g., ButtonElement.class)

Scroll Methods

scrollToRow

Scroll the list so the given row index becomes visible.
void scrollToRow(int rowIndex)
rowIndex
int
0-based row index

scrollToStart

Scroll to the very beginning of the list.
void scrollToStart()

scrollToEnd

Scroll to the very end of the list.
void scrollToEnd()

Assertion Methods

assertRowCount

Assert the total number of items matches the expected count.
void assertRowCount(int expected)
expected
int
Expected row count

assertRowInView

Assert that the given row index is currently visible.
void assertRowInView(int rowIndex)
rowIndex
int
0-based row index

assertRowNotInView

Assert that the given row index is NOT currently visible.
void assertRowNotInView(int rowIndex)
rowIndex
int
0-based row index

assertFirstVisibleRow

Assert that the first visible row index equals the expected value.
void assertFirstVisibleRow(int expected)
expected
int
Expected first visible row index

assertLastVisibleRow

Assert that the last visible row index equals the expected value.
void assertLastVisibleRow(int expected)
expected
int
Expected last visible row index

assertItemRendered

Assert that an item containing the given text is currently rendered.
void assertItemRendered(String text)
text
String
Text to look for

assertEmpty

Assert the list has zero items.
void assertEmpty()

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);

Scroll and Check Visibility

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();

Scroll to Specific Position

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());

Build docs developers (and LLMs) love