Rayrun
← Back to Discord Forum

`getByRole('definition', { name: 'Status' })` not working but works in Testing Playground

Given markup like the following:

<dl>
  <div>
    <dt id="ticket-status">Status</dt>
    <dd aria-labelledby="ticket-status">open</dd>
  </div>
  <div>
    <dt id="ticket-team">Team</dt>
    <dd aria-labelledby="ticket-team">My Team</dd>
  </div>
</dl>

Using the following selector:

await expect(
  page.getByRole('definition', { name: 'Status' })
).toBeVisible()

Expected

The <dd> containing "open" labeled by "Status" would be selected and the test passes.

Actual

The element is never found and an error is thrown

More Context

The odd part is that if I open the Testing Playground Chrome Extension, then evaluate:

screen.getByRole('defintion', { name: 'Status' })

That seems to work.

This thread is trying to answer question "Why does 'getByRole('definition', { name: 'Status' })' not work in the testing code but works in the Testing Playground Chrome Extension?"

1 reply

Would suggest taking the time to read up on locators and understand how they works, plentiy of youtube videos covering them too...

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.