I have a basic Playwright locator:
page.locator('.some-table tbody tr');
I'm trying to use it to test a paginated table with 100 rows per page. When I run my test:
const rows = page.locator('.some-table tbody tr');
expect(await rows.count(), '# of rows').toEqual(100);
the first page passes, as expected.
However, when I run an identical test, after clicking a button to go to page #2, it fails, because it sees a 101 total rows.
Now, I've confirmed in my browser (with $$('.some-table tbody tr').length
) that both pages have exactly 100 rows. Also, I can iterate through all the rows, and their content lines up with what I see on the page ...
... except on page #2. When I loop through all the rows on page #2:
const rows = await page.locator('.some-table tbody tr').all();
for (const row of rows) {
console.log('\n', await row.textContent(), i);
}
the test times out when it tries to get the textContent
of the "ghost" 101st row. All 100 rows before log their contents just fine, but row #101 times out.
If I try logging the innerHtml
instead, the same thing happens:
Test timeout of 30000ms exceeded.
Error: locator.innerHTML: Test timeout of 30000ms exceeded.
In summary, Playwright is finding a 101st row on page #2, but not on page #1 (even though both have 100 rows only). I have no idea where this "ghost" row is coming from, and I can't even figure anything out about it, because it times out whenever I try to see its details.
Does anyone have any idea how I can resolve this?
With help from @ggorlen I realized that I could inspect the "ghost row" by inspecting its parent instead. In other words, instead of doing the following (in a loop):
console.log('\n', await row.textContent(), i);
I did this (without looping):
console.log('\n', await page.locator('.some-table tbody').innerHtml());
This at least let me log the tbody
's HTML, so I could see my "ghost row" ... although there was so much HTML in that log that it actually got truncated, and I had to split the (very long) string into several smaller strings in order to actually see them in the logs.
Sadly, doing all that didn't give me any further insight into why Playwright was finding a ghost row ... but I did discover that by adding an extra second of wait, I could eliminate the ghost.
So, unfortunately there's no satisfying answer as to the mystery of the ghost row itself, but at least (again, thanks to @ggorlen) I was able to figure out how to "inspect" that row.