Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/javascript-api/k6-browser/page/getbyplaceholder.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/k6-browser/page/getbyplaceholder/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
getByPlaceholder(placeholder[, options])
Returns a locator for input elements with the specified placeholder attribute. This method is useful for locating form fields that use placeholder attribute to provide hints or examples to users about the expected input format.
| Parameter | Type | Default | Description |
|---|---|---|---|
placeholder | string | RegExp | - | Required. The placeholder text to search for. Can be a string for exact match or a RegExp for pattern matching. |
options | object | null | |
options.exact | boolean | false | Whether to match the placeholder text exactly with case sensitivity. When true, performs a case-sensitive match. |
Returns
| Type | Description |
|---|---|
| Locator | A locator object that can be used to interact with the input elements matching the specified placeholder text. |
Example
Find and fill inputs by their placeholder text:
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
await page.setContent(`
<input type="text" placeholder="First name">
<input type="text" placeholder="Last name">
<input type="text" placeholder="dd/mm/yyyy">
<input type="text" placeholder="your.email@example.com">
<input type="text" placeholder="+1 (555) 123-4567">
`);
await page.getByPlaceholder('First name').fill('First');
await page.getByPlaceholder('Last name').fill('Last');
await page.getByPlaceholder('dd/mm/yyyy').fill('01/01/1990');
await page.getByPlaceholder('your.email@example.com').fill('first.last@example.com');
await page.getByPlaceholder('+1 (555) 123-4567').fill('+1 (555) 987-6543');
} finally {
await page.close();
}
}Common use cases
- Form field identification:
- Login and registration forms without explicit labels
- Quick search boxes
- Filter and input controls
- Comment and feedback forms
- E-commerce:
- Product search bars
- Quantity input fields
- Promo code entry
- Address and payment information
- Interactive applications:
- Chat input fields
- Command input interfaces
- Settings and configuration forms
- Data entry applications
Best practices
- Complement, don’t replace labels: Placeholder text should supplement, not replace proper form labels for accessibility.
- Use descriptive placeholders: Ensure placeholder text clearly indicates the expected input format or content.
- Consider internationalization: When testing multi-language applications, be aware that placeholder text may change.
- Accessibility considerations: Remember that placeholder text alone may not be sufficient for users with disabilities.
Related
- page.getByRole() - Locate by ARIA role
- page.getByAltText() - Locate by alt text
- page.getByLabel() - Locate by form labels (preferred for accessibility)
- page.getByTestId() - Locate by test ID
- page.getByTitle() - Locate by title attribute
- page.getByText() - Locate by visible text
Was this page helpful?
Related resources from Grafana Labs

