← Back to library
Playwrightselectorsbeginnerv1.20+
getByPlaceholder — fill by placeholder text
Locate an input by its placeholder attribute — useful for search bars and inline forms without visible labels.
1test('searches using the placeholder-located input', async ({ page }) => {
2 await page.goto('/library');
3
4 // getByPlaceholder is ideal when there is no visible <label>
5 await page.getByPlaceholder('Search snippets...').fill('playwright drag');
6 await page.getByPlaceholder('Search snippets...').press('Enter');
7
8 await expect(page.getByTestId('results-list')).toBeVisible();
9});#getByPlaceholder#placeholder#search#input