Skip to content
masterclass Buddy

Playwright · Method

locator.count

locator.count() returns the number of elements matching a locator. Use expect(locator).to_have_count() for count assertions to reduce flakiness.

Last updated

Since
v1.14

Syntax

locator.count()

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

Subscribe
  • locator
  • expect(locator).toHaveCount()
  • get_by_role

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