Rayrun
← Back to Discord Forum

GetByRole name is not exact?

Was wondering was there a change with GetByRole that the name given is not exact?

Error: locator.click: Error: strict mode violation: getByRole('button', { name: 'Save' }) resolved to 2 elements: 1) <button granitebutton="" _nghost-cso-c107="" aria-haspop…>…</button> aka getByRole('button', { name: 'Saved Searches' }) 2) <button title="Save" disabled="true" granitebutton="" _n…>…</button> aka getByRole('button', { name: 'Save', exact: true })

Previously it ran correctly but should I now add to each locater the exact:true option?

This thread is trying to answer question "Was there a change with GetByRole that the name given is not exact?"

7 replies

I am now on 1.35

debbieobrien
debbieobrien

exact boolean (optional)#

Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.

debbieobrien
debbieobrien

exact was added in: v1.28

You can also do: getByRole('button', { name: 'Save', exact: true })

I noticed getByText also matches in the same manner .... is there away to make those locators to default to exact?

Not as of today. We had the feature request for this somewhere if I remember correctly.

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 [email protected].