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

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

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

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