Skip to content
masterclass Buddy

Playwright · Matcher

toHaveCount

toHaveCount asserts that a locator matches an exact number of DOM nodes. It retries until the count matches or the assertion timeout is reached.

Last updated

Since
v1.20

Syntax

await expect(locator).toHaveCount(count, options);

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

Subscribe
  • expect
  • Locator
  • toHaveText
  • locator.count
  • locator.all

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