RepoPilot

What's the recommended way to select an element by text in Playwright?

About microsoft/playwright · 2 messages · last activity 7/5/2026

Question

What's the recommended way to select an element by text in Playwright?

RepoPilot

The search returned matcher implementation details but not locator selection methods. Based on what's visible in the repository data, the README example shows the way to select by text in Playwright:

page.getByRole('link', { name: 'Get started' })

This demonstrates using getByRole() with the name option to select elements by their accessible text content. This is the web-first approach Playwright recommends.

The repository shows text-matching is deeply integrated into Playwright's assertion system through matchers like toHaveText() which support both string and RegExp patterns [packages/playwright/src/matchers/matchers.ts:L392-L410], but the specific locator selection APIs (like getByText(), getByLabel()) aren't shown in the retrieved chunks.

FOLLOW_UPS:

  • What locator strategies does Playwright support?
  • How do you select elements by role in Playwright?
  • How do regex patterns work in Playwright assertions?

Want to ask your own question?

Open chat for microsoft/playwright

Public Q&A. Generated by RepoPilot from the actual source of microsoft/playwright. AI answers can be incomplete or stale — verify before relying on them.