Skip to content
masterclass Buddy

Playwright · Matcher

toHaveText

Checks that a locator's element or elements have the expected text. It supports strings, regular expressions, and ordered arrays of expected values.

Last updated

Since
v1.20

Syntax

await expect(locator).toHaveText(expected, options);

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

Subscribe
  • Locator
  • expect
  • toContainText
  • toHaveValue
  • toHaveAttribute

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