Skip to content
masterclass Buddy

Playwright · Matcher

toHaveRole

toHaveRole checks that a locator points to an element with a specific ARIA role. It retries until the role matches or the assertion timeout is reached.

Last updated

Since
v1.44

Syntax

await expect(locator).toHaveRole(role, options);

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • expect
  • Locator
  • getByRole
  • getByTestId
  • toBeVisible
  • toHaveAccessibleName

Source: LocatorAssertions | Playwright. Checked 2026-11-03.