k6 icon indicating copy to clipboard operation
k6 copied to clipboard

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

Open ankur22 opened this issue 6 months ago • 0 comments

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)

https://github.com/grafana/k6/issues/4248

ankur22 avatar May 15 '25 12:05 ankur22