Skip to content
masterclass Buddy

Playwright · Method

locator.getAttribute

Reads an attribute from the element matched by a locator. It returns the attribute value or null when the attribute is missing.

Last updated

Since
v1.14

Syntax

locator.getAttribute(name)
locator.getAttribute(name, options)

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

Subscribe
  • Locator
  • expect(locator).toHaveAttribute()
  • getByRole
  • page.locator()

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