Simulating Enter Key Press Not Working in Puppeteer

I’m trying to simulate an Enter key press in Puppeteer but it’s not working as expected. I found the documentation about key pressing but something seems wrong with my implementation.

Here’s my current approach:

// Click on the text input
await page.click('.header-section .search-area input[name="query"]');
// Set focus to the input element
await page.focus('.header-section .search-area input[name="query"]');
// Type search text
await page.type("Hello World");
// Try to press Enter key - this part fails!
await page.press("Enter");

The Enter key press doesn’t seem to trigger anything. The form doesn’t submit and nothing happens. What’s the correct way to simulate pressing Enter to submit a form in Puppeteer?

double-check the input is focused b4 pressing enter. adding await page.waitForTimeout(100) just b4 the press can help; sometimes it needs a moment to catch up.

Had this exact problem last month. Your page.type() call is missing the selector parameter. You’re calling await page.type("Hello World") but it should be await page.type('.header-section .search-area input[name="query"]', "Hello World"). Without the selector, the text isn’t actually getting typed into the input field, so when you press Enter there’s nothing to submit. Also check if the form has JavaScript event handlers preventing the default Enter behavior. Test this by manually typing in the input and pressing Enter to see if it works outside of Puppeteer.

You’re not passing a selector to the press method. When you call await page.press("Enter"), Puppeteer doesn’t know which element gets the keypress. Try this instead: await page.press('.header-section .search-area input[name="query"]', 'Enter'). Or use await page.keyboard.press('Enter') to send the keypress to whatever’s currently focused. I’ve hit this same issue before - the selector approach works better since it targets the right element even if focus changes.