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 Amazon.in placeholder value comes from the placeholder attribute of an element.

<input type="text"" placeholder="Search Amazon.in" 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.

Example

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

test('Get By Placeholder', async ({ page }) => {
    await page.goto("https://www.amazon.in/");
    await page.getByPlaceholder("Search Amazon.in").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