Skip to content

Implement page.getByPlaceholder(placeholderText: string, options?) #4790

@ankur22

Description

@ankur22

Feature Description

With a getByPlaceholder method, k6 Browser scripts can target inputs or textareas by their placeholder attribute: e.g., page.getByPlaceholder('Search…'). This is particularly useful for quick form tests where the placeholder uniquely identifies a field. The implementation would locate all input and textarea elements with a matching placeholder, respecting options for matcher type (exact, regex, etc.). This addition reduces the need for ad-hoc CSS selectors and mirrors best practices in modern test automation.

Playwright docs: https://playwright.dev/docs/api/class-page#page-get-by-placeholder

Note: this is only to be implemented on page.

This should work after the implementation work:

  await page.setContent(`
    <html><body>
      <input placeholder="Search…" />
    </body></html>
  `);
  const searchInput = page.getByPlaceholder('Search…');
  await searchInput.fill('playwright');

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

#4248

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions