Playwright Get By Placeholder

Profile picture for user devraj

A placeholder is a text inside an input element, which hints to a user what value should be entered. You will find a placeholder in the search bar or different form elements.

get by placeholder playwright

Search placeholder value comes from the placeholder attribute of an element.

<input type="text"" placeholder="Search" spellcheck="false">

If you want to find and work with an input field with a placeholder text inside it, you can use the playwright getByPlaceholder() function.


Let's search for "avengers slap bands" using placeholder text.

test('Get By Placeholder', async ({ page }) => {
    await page.goto("");
    await page.getByPlaceholder("Search").fill("avengers slap bands");

When to Use

You should use the getByPlaceholder() function when trying to find and work with elements in a form that does not have labels but has placeholder text. When the label is present, you can use the getByLabel() function instead.

Video Tutorial: Get By Placeholder Playwright