Use Playwright's semantic locators (getByRole, getByText, getByLabel) and rely on built-in auto-waiting instead of manual sleeps

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Prefer role-based locators such as `page.getByRole('button', { name: 'Submit' })` over CSS selectors to align with the accessibility tree and survive minor DOM refactors.
  2. Use `getByLabel` for form inputs, `getByPlaceholder` for unlabelled inputs, and `getByTestId` when the team controls test-id attributes — each targets a stable semantic attribute.
  3. Chain locators with `.filter({ hasText: '...' })` or `.nth(0)` to narrow results when a role matches multiple elements.
  4. Call action methods (`click`, `fill`, `check`) directly on the locator; Playwright automatically waits for the element to be visible, stable, enabled, and not obscured before acting — no explicit `waitForSelector` needed.
  5. Use `expect(locator).toBeVisible()` and other web-first assertions from `@playwright/test`; they retry until the condition is met or the timeout expires, eliminating most race conditions.

Known gotchas

Related routes

Run Browser Use agent loop with a custom LLM to automate web tasks via Playwright
github.com/browser-use/browser-use · 6 steps · unrated
use puppeteer's locators api for auto-waiting, retrying element interactions
pptr.dev · 5 steps · unrated
Automate elements inside cross-origin iframes with Playwright's frameLocator, understanding where site-isolation limits still apply
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans