Skip to content
masterclass Buddy

Playwright · Matcher

toHaveAttribute

Checks that a locator's element has a named attribute. It can compare the value, match a regular expression, or check only that the attribute exists.

Last updated

Since
v1.20

Syntax

await expect(locator).toHaveAttribute(name, value, options);

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

Subscribe
  • Locator
  • LocatorAssertions.not
  • toHaveText
  • toHaveClass
  • getAttribute

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