An event site lists workshops in a table. Each row has a Reserve button, so a page-wide search for that button can match several actions. Start from the row that contains the session's name, then find the button inside it.
const row = page.getByRole('row').filter({ hasText: 'Printmaking' });
await expect(row).toHaveCount(1);
await row.getByRole('button', { name: 'Reserve', exact: true }).click();
await expect(page.getByRole('heading', { name: 'Reserve Printmaking' }))
.toBeVisible();
Run the test with another workshop above Printmaking. Then reverse the sort order. Both runs should reach the Printmaking reservation page, even though the row index changes. If two workshops share a title, scope to a date or another name the page exposes alongside it. Make the uniqueness assertion strict enough for the fixture you actually have.
A role locator also gives you a quick check on the accessible name of the button. Try changing its visible text to Join waitlist in a test fixture. The original locator should fail. Update the test when the product deliberately changes the action, and keep the final heading assertion so a button with the right name cannot silently send readers to the wrong page.
Scope to a unique cell when workshop names are similar
Add a fixture row titled “Advanced Printmaking.” The original text filter can match that row as well as “Printmaking.” Give the row filter an exact cell locator to make the distinction explicit.
const title = page.getByRole('cell', { name: 'Printmaking', exact: true });
const row = page.getByRole('row').filter({ has: title });
await expect(row).toHaveCount(1);
Keep the Reserve lookup inside that row. Rerun the fixture in both sort orders and check the resulting reservation heading. If the table has two sessions with the same title, add a second filter using the displayed date or time and assert the destination shows that session.
