Skip to content

[Feature]: table/grid locators for targeting cells by row/column index or labels聽#40248

Closed

Description

馃殌 Feature Request

There doesn't appear to be an easy way to select a cell in a similar way to how a user would do it. This makes interactive grids and data tables a little bit awkward to work with using getByRole(). Maybe we can expand the options in getByRole()?

New options

Option Type Description
rowIndex number Targets elements based on row index, either inferred or assigned with aria-rowindex. Applies to table and grid roles.
columnIndex number Targets elements based on column index, either inferred or assigned with aria-colindex. Applies to table and grid roles.
rowLabel string | RegExp | string[] | RegExp[] Targets elements based on the accessible name(s) of one or more row headers present in the same row. Applies to table and grid roles.
columnLabel string | RegExp | string[] | RegExp[] Targets elements based on the accessible name(s) of one or more column headers present in the same row. Applies to table and grid roles.

Example

test("I can change a cell value", ({ page }) => {
  const cell = page
    .getByRole("table", { name: "My Table" })
    .getByRole("cell", { rowLabel: "Gross Profit", columnLabel: "April 2026" });

  expect(cell).toContainText("拢 0");
  cell.pressSequentially("123")
  cell.press("Enter");
  expect(cell).toContainText("拢 123");
});

Motivation

It's nice to use accessibility-first locators like getByRole(). They make tests resilient and force developers to build applications with the correct roles and attributes. Having a way to locate a cell in the same way a user would (via the row/column headers or row/column index) would improve E2E tests that target tables and interactive data grids.

I see #33111 is asking for some table helpers, but this request is more focused on extending getByRole() in the same way that other options like selected or pressed work.

Activity

  1. yury-s commented on Apr 16, 2026

    @yury-s
    Member

    Folding into #4646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions