In Playwright wait for data rows to be loaded on page

42 views Asked by At

I open page and waiting until data is loaded to displayed rows. In selenium it works like this:

private final String dataRowXpath = "*//div[@ref='eCenterContainer']//div[@role='row']";
WebDriverWait wait = new WebDriverWait(driver, ofMinutes(1L));
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.xpath(dataRowXpath), 0));

I need to do it using Playwright. I written below code:

String dataRowCSSSelector = div[ref='eCenterContainer'] > div[role='row']
String function = String.format("() => document.querySelectorAll(\"%s\").length > 0", dataRowCSSSelector);
page.waitForFunction(function);

But unfortunately it throws timeout exception although I see that data rows are loaded:

com.microsoft.playwright.TimeoutError: Error {
  message='Timeout 30000ms exceeded.
  name='TimeoutError
  stack='TimeoutError: Timeout 30000ms exceeded.
1

There are 1 answers

3
szogoon On

Why are you not using Playwright locators?

https://playwright.dev/java/docs/locators#strictness

Try with this:

assertThat(page.locator("*//div[@ref='eCenterContainer']//div[@role='row']").first()).isVisible();