Sponsored Link
Looking for a unified way to  viewmonitor, and  debug Playwright Test Automation runs?
Try the Playwright Dashboard by today. Use the coupon code PWSOL10 for a 12 month 10% discount.

Access a Table Row With Unique Text From a Cell in Playwright

There are a ton of different ways to interact with tables, this is the first of many examples of different ways you can extract/confirm data exists where it should in your Playwright Tests.

For this example we will use the table found at https://letcode.in/table

For this challenge I want to get the entire row with values for Cupcake. Playwright has a very nice locator function, which allows us to specify a high level element tr and find the table row that has-text Cupcake. This will return the locator for the table row in order to make assertions or interact in other ways with the entire row.

import { test } from "@playwright/test";

test("get entire row from table from text in a cell", async ({ page }) => {
  await page.goto("https://letcode.in/table");

  const row = page.locator('tr:has-text("Cupcake")');

If you were to console.log(row.innerText()) you would get the below returned.