Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright’s semantic locators to find a table, select a header by its columnheader role and accessible name, then verify the header or cell with a web-first assertion such as expect(locator).toHaveText(). For a value in a particular column, first identify the intended row; use a numeric cell position only when the table’s column order is a reliable part of your test contract.

Select a table header by role and accessible name

Start by locating the table, then search within it for a column header. Scoping the search helps avoid matching a similarly named header elsewhere on the page. Playwright’s locator guidance favors user-facing semantics such as roles and accessible names; table-related roles include table, row, cell and columnheader.

import { test, expect } from '@playwright/test';

test('select a table header', async ({ page }) => {
  const table = page.getByRole('table', { name: 'Orders' });
  const statusHeader = table.getByRole('columnheader', {
    name: 'Status',
    exact: true,
  });

  await expect(statusHeader).toBeVisible();
  await expect(statusHeader).toHaveText('Status');
});

The table name and header name must match the accessible names exposed by the page. exact: true is useful when a broader match could select a different header—for example, “Status” rather than “Status details.” If the table has no accessible name, inspect its markup and accessibility semantics, then use another deliberate locator strategy rather than assuming a name.

When a role locator does not find the table

A locator using getByRole('table') depends on the rendered page exposing table semantics. If the interface is built from generic elements without appropriate roles, or the intended element is not accessible in the way the test expects, the role locator may not match. Prefer fixing or clarifying the application’s semantic markup when possible. If that is not practical, use an explicit test contract such as a test id, or use a carefully scoped text or CSS locator as a fallback.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Verify every header and its order

To verify a complete header row, assert against the collection of column headers in the expected order:

await expect(table.getByRole('columnheader'))
  .toHaveText(['Order', 'Status', 'Total']);

An array passed to toHaveText() checks the matched elements in order and checks the locator’s count against the array. This makes it useful for catching missing, extra, or reordered headers—not just checking that each label appears somewhere. Scope the collection to the intended table so unrelated headers elsewhere on the page cannot affect the result.

toHaveText() is a web-first assertion: it retries until the expected condition is met or the configured expect timeout is reached. String expectations normalize whitespace, including line breaks. Regular-expression expectations are matched against the actual text as-is. The assertion considers nested text, so a header containing nested markup can still be checked by its rendered text.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Choose the assertion that matches the requirement

  • One header: locate that columnheader by role and accessible name, then assert its text.
  • All headers in order: assert the scoped header locator against an ordered array of expected strings.
  • Variable text pattern: use a regular expression when the expected label legitimately varies, and account for the fact that regex matching does not normalize whitespace like string expectations.
  • Form control value: if the thing being checked is an input or another form control in or near a table, assert its value with toHaveValue(). For ordinary rendered cell text, use toHaveText().

Assert a cell value under a named column

When rows and cells expose reliable semantics, find the row first and make the assertion within that row. For example, if the table contains a row identifiable by “Order 123,” the following checks that the row is unique and that its second cell contains “Shipped”:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const row = table.getByRole('row').filter({ hasText: 'Order 123' });
await expect(row).toHaveCount(1);
await expect(row.getByRole('cell').nth(1)).toHaveText('Shipped');

Locator chaining keeps the cell search inside the matched row, while filter({ hasText }) narrows the row locator by its text. The count assertion matters: without it, a broad row match could make the test ambiguous or allow the wrong record to be checked.

Do not treat a cell index as the column name

nth(1) selects the second matching cell because Playwright indices are zero-based. It does not mean “the Status column.” This example is safe only if the application’s column order is stable and that ordering is part of the test’s assumptions. If columns can be reordered, inserted, or hidden, a test that keeps using index 1 may check a different field while still passing.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

For a changeable layout, establish a reliable contract between the header and cells rather than hard-coding an unexplained position. One option is a stable test id on the relevant cells. Another is to determine the rendered header position and use that position only when the markup and table layout make the header-to-cell mapping unambiguous. The locator and assertion shown above do not themselves derive a position from the header; treat the index as application-specific.

Make asynchronous tables reliable

Tables populated after a network request or client-side render may initially have no rows, partial rows, or stale rows. Do not immediately read a changing collection and assume it is complete. Playwright documents that locator.all() returns the elements that match at that moment; it does not wait for a changing list to settle and can produce unpredictable results when the list is dynamic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prefer an assertion on the expected state, which retries while the page updates:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
await expect(table.getByRole('columnheader'))
  .toHaveText(['Order', 'Status', 'Total']);

If the headers do not establish readiness—for example, the table renders its headings before fetching rows—wait for an expected row or other stable, user-visible condition before inspecting a collection. Choose a condition that represents the state the test actually needs. A fixed delay can be slower than necessary and does not prove that the table is ready; a web-first assertion checks the target state itself.

Choose resilient locators and diagnose failures

Semantic role-and-name locators are usually easier to understand and less coupled to a particular DOM shape than selectors that encode element ancestry or position. Playwright supports CSS and XPath through page.locator(), but selectors tied to DOM structure can break when the implementation changes. Use them when there is a good reason, not as the automatic first choice.

Symptom Likely cause What to check or change
No table or header matches The accessible role or name differs from the locator, or the interface does not expose table semantics. Inspect the rendered semantics and accessible name. Correct the locator to match the user-facing interface, or use an explicit test contract if semantic roles are unavailable.
More than one matching table or row The locator is too broad, or its identifying text appears in multiple rows. Scope to the intended table and use a more specific row identifier. Assert the expected count before checking a cell.
A header assertion passes but a cell check is wrong A positional cell index no longer corresponds to the assumed column. Confirm the rendered column order. If it is not fixed, use a stable cell contract or explicitly associate the header with its column before selecting the cell.
Flaky results while rows are loading The test reads a changing collection before it reaches the required state. Wait for the expected header or row with a retrying assertion before performing any collection-based work. Avoid relying on locator.all() as a wait.
Text assertion fails despite seemingly matching content Whitespace, line breaks, nested text, or a regex expectation may differ from the visible string. Use a string expectation when whitespace normalization is appropriate; remember regex matching uses actual text as-is. Check whether the cell is rendered text or a form control value.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a visual record of a table page rather than an assertion in a Playwright test, ScreenshotNeo can return a screenshot from one GET request. It is a website screenshot API and MCP server, not a replacement for Playwright’s locator and assertion APIs: use the Playwright method above when the test must verify that a header or cell has a particular value.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Before a capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response reports its page verdict and billing status in X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Plans and features are described at ScreenshotNeo.

Sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Can I use `getByRole(‘cell’)` to select a table value?

Yes, when the rendered table exposes cell semantics. Scope the cell locator to the intended row or table so the assertion targets the right value.

Should I use `toHaveText()` or `toContainText()` for a header?

Use `toHaveText()` when the expected text should match the locator’s text; use a looser containment check only when additional text is intentional.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does ScreenshotNeo verify that a table cell has the expected value?

No. It captures a page visually; use Playwright locators and assertions to test rendered table text.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.