Virtualized list practice
Practice a virtualized list: 1,000 orders, but only the twenty or so rows on screen exist in the DOM. Rosa Quinn’s order, ORD-742, is not on the page until you scroll to it, and on v2 the list runs the other way. Open the admin orders table
1,000-row virtualized listScroll to ORD-742 (Rosa Quinn). Rows outside the view are removed, not hidden.
Built well
Built to break
Tasks: write a locator, get a grade
How to locate Virtualized lists
The row you want does not exist yet
Virtualized lists (react-window, TanStack Virtual, AG Grid, most data grids) render only the rows in view plus a few spare. Scroll, and rows leaving the view are removed while new ones are created. A locator for ORD-742 matches nothing on page load, not because it is wrong but because the row has not been built.
Row position means nothing here. The fifth row element in the DOM is whatever happens to be fifth in the current window, and on v2 the list is reversed, so ORD-742 sits near row 259 instead of row 742. Absolute positions from transform or top change with every scroll.
Recycling makes it worse: some libraries reuse row elements for new data, so a reference you held to a row can quietly start pointing at a different order after a scroll.
What a stable locator looks like
Locate by content, then scroll until it exists. Find the grid by its test id or name, scroll it a step at a time, and stop when the row with the order id appears. aria-rowindex tells you where a row sits in the full list, and aria-rowcount how many rows there are, so you can jump close before stepping. Rows here also carry data-customer, an attribute the app owns that names the record without a generated-looking number. Never keep a row reference across a scroll; locate it again.
const list = page.getByTestId('order-list');
const row = list.locator('[data-customer="Rosa Quinn"]');
// Scroll the list until the row is rendered, then use it
while (!(await row.count())) {
await list.evaluate((el) => el.scrollBy(0, el.clientHeight));
}
await expect(row).toContainText('ORD-742');In a real workflow
The admin orders screen has a 500-row virtualized archive under the orders table. Sign in to the admin and bring ORD-1450 into view without counting rows.
COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the virtualized lists above with it and compare its pick with yours.
Add to Chrome