Rayrun
← Back to Discord Forum

locating by name property is failing

I have a button that has a name property, such as <button class="MuiButtonBase-root MuiButton-root MuiButton-text jss43" tabindex="0" type="button" name="organization-dropdown"><span class="MuiButton-label"></button>

And when I use await page.getByRole("button", { name:'organization-dropdown', exact: true, }).toBeVisible()

I get a timeout and its not found When I test it in headed I can see the button exists so i am guessing that the getByRole is not working as I expect

Any help would be greatly appreciated

This thread is trying to answer question "Why is locating a button by its name property using getByRole in Playwright failing and resulting in a timeout?"

6 replies

I would browse to the page in Playwright Inspector and use the pick locater to let it suggest a locator for you. Might explain what is going wrong.

Also, I have found that sometimes .toBeVisible() returns false when I would expect it to be true.

I use .toHaveCount(1) instead

tphillips8117

Yeah toBeVisible() is quite specific: "Ensures that Locator points to an attached and visible DOM node." https://playwright.dev/docs/actionability#attached https://playwright.dev/docs/actionability#visible

@narm24: Name is for the label in getByRole.

Name is for the label in getByRole.

Thanks everyone

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