Inputs
Different input types for practicing form interactions with Playwright.
Typing into inputs
Find inputs by their label
Every field here has a <label>, so getByLabel() finds it the way a user reads the form. Test ids work too, but labels also check that the form is accessible.
const username = page.getByLabel('Username');
await username.fill('tester');
await expect(username).toHaveValue('tester');
await expect(page.getByTestId('username-result')).toContainText('tester');fill() or pressSequentially()?
fill()replaces the whole value in one go. Use it by default.pressSequentially()types one key at a time, like a person. Use it when the page reacts to each keystroke, such as autocomplete.clear()empties a field.
Special input types
Date, range and other special inputs are filled with a plain string too. Dates always use YYYY-MM-DD, whatever format the browser displays.
await page.getByLabel('Date').fill('2026-05-17');
await page.getByLabel(/Range/).fill('75');The range label also contains the current value, so a regular expression matches it whatever the number is.
Text input
You entered:
Other inputs
Summary:
- Email: N/A
- Password: N/A
- Number: N/A
- Date: N/A
- Range: 50
Next in Basic Elements · 3 of 6Checkboxes →Change checkbox states and assert both the inputs and the state summary.
Related exercises
- FormsIntermediateForm ValidationTest validation rules wherever they run: on submit, on the server, when a field loses focus, and in the browser itself.
- Mouse & KeyboardBeginnerKeyboard ActionsDrive the page with the keyboard alone: typing, Tab order, shortcuts and held keys.
- Content & AttributesIntermediateAttributes vs PropertiesTell the HTML attribute apart from the live property, and use data attributes.
Read the guide: Playwright practice for beginners: a four-week plan