sincecutoff.com
← all changes

Playwright locator.visible() filters to visible elements

Introduced 2026-09-04 · score 0.97

HOW TO USE IT

When clicking a matching button only if it is visible, use `await page.locator('button').visible().click();`. `visible()` returns a locator that filters out invisible elements and is the recommended replacement for `:visible`.

await page.locator('button').visible().click();

WHY THIS HELPS

Click a matching button only when it is visible.

BEFORE THIS CHANGE

Use the `:visible` CSS pseudo-class to match visible elements.

REQUIREMENTS AND LIMITATIONS

  • Version: v1.63.0
  • selector (`'button'`) (required): The selector passed to `page.locator()` to find matching elements.
  • `visible()` (required): Takes no documented arguments; returns a locator matching only visible elements. Visibility is checked each time the locator is used.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card