Because it was driving me insane, and because I don't want to ever forget...

Playwright is a wonderful alternative to jest-puppeteer for doing automated headless browser end-to-end testing. But one I couldn't find in the documentation, Google search, or Stackoverflow was: How do you submit a form without clicking a button?. I.e. you have focus in an input field and hit Enter. Here's how you do it:


await page.$eval('form[role="search"]', (form) => form.submit());

The first part is any CSS selector that gets you to the <form> element. In this case, imagine it was:


<form action="/search" role="search">
  <input type="search" name="q">
</form>

You, or my future self, might be laughing at me for missing something obvious but this one took me forever to solve so I thought I'd better blog about it in case someone else gets into the same jam.

UPDATE (Sep 2021)

I found a much easier way:


await page.keyboard.press("Enter");

This obviously only works when you've typed something into an input so the focus is on that <input> element. E.g.:


await page.fill('input[aria-label="New shopping list item"]', "Carrots");
await page.keyboard.press("Enter");

Comments

Your email will never ever be published.

Previous:
How to install Python Poetry in GitHub Actions in MUCH faster way July 27, 2021 Python
Next:
Shut the door! How to automate getting the kids to close the door August 23, 2021 Family
Related by category:
Always run biome migrate after upgrading biome August 16, 2025 JavaScript
Video to Screenshots app June 21, 2025 JavaScript
How to handle success and failure in @tanstack/react-query useQuery hook September 16, 2024 JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
Related by keyword:
html-getter - A powerfully simple HTML scraper in Bun April 17, 2026 Bun, macOS, TypeScript
The technology behind You Should Watch January 28, 2023 React, Firebase, JavaScript, You Should Watch
How to use minimalcss without a server April 24, 2020 Web development, Node, JavaScript
How's My WiFi? December 8, 2017 Node, JavaScript, macOS