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