Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Locator.press('Enter') on the field or control that should receive the key. Playwright focuses that element and sends the logical Enter key. Use page.keyboard.press('Enter') only when focus is intentionally managed at page level.
The preferred Playwright pattern
Target the control that owns the interaction, then press the logical key name:
await page.getByRole('textbox').press('Enter');
Locator.press() focuses the matching element before producing the key event. That makes the test independent of whatever happened to have focus previously. The key name is Enter, with an uppercase E.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →A locator can include a role, accessible name, label, placeholder, or another stable attribute. For example:
#1 Best Overall
- KEYBOARD: The keyboard works for Windows with hot keys that enable easy access to Media, My Computer, Mute, Volume up/down, and Calculator
- EASY SETUP: Experience simple installation with the USB wired connection
- VERSATILE COMPATIBILITY: This keyboard is designed to work with multiple Windows versions, including Vista, 7, 8, 10 offering broad compatibility across devices.
- SLEEK DESIGN: The elegant black color of the wired keyboard complements your tech and decor, adding a stylish and cohesive look to any setup without sacrificing function.
- FULL-SIZED CONVENIENCE: The standard QWERTY layout of this keyboard set offers a familiar typing experience, ideal for both professional tasks and personal use.
await page.getByRole('textbox', { name: /search/i }).press('Enter');
Playwright also accepts combinations written with plus signs, such as Control+Enter, Meta+Enter, and Control+Shift+T.
Complete JavaScript and TypeScript example
This test fills a search field, presses Enter on that field, and checks the resulting URL:
import { test, expect } from '@playwright/test';
test('submits search with Enter', async ({ page }) => {
await page.goto('https://example.test/search');
const search = page.getByRole('textbox', { name: /search/i });
await search.fill('playwright');
await search.press('Enter');
await expect(page).toHaveURL(/results/);
});
The locator method is preferable here because the key is sent to the search control rather than to whichever element currently has focus. The URL assertion waits for the resulting page state instead of assuming that the action completed instantly.
Free tools Windows power users keep installed
One-click scans. No signup required.
Python, Java and C# equivalents
Python
from playwright.sync_api import Page
def test_search_with_enter(page: Page):
page.goto("https://example.test/search")
search = page.get_by_role("textbox", name="Search")
search.fill("playwright")
search.press("Enter")
The Python API exposes the same logical key behavior: identify the element, focus it, and call press("Enter").
Java
Locator search = page.getByRole(AriaRole.TEXTBOX,
new Page.GetByRoleOptions().setName("Search"));
search.fill("playwright");
search.press("Enter");
C#
var search = page.GetByRole(AriaRole.Textbox,
new() { Name = "Search" });
await search.FillAsync("playwright");
await search.PressAsync("Enter");
Method names differ by language, but the sequence is identical: locate the intended control, enter text, then send Enter.
Pressing Enter to submit a form
For a form that submits when a field receives Enter, press the key on that field after filling it:
Rank #2
- All-day Comfort: The design of this standard keyboard creates a comfortable typing experience thanks to the deep-profile keys and full-size standard layout with F-keys and number pad
- Easy to Set-up and Use: Set-up couldn't be easier, you simply plug in this corded keyboard via USB on your desktop or laptop and start using right away without any software installation
- Compatibility: This full-size keyboard is compatible with Windows 7, 8, 10 or later, plus it's a reliable and durable partner for your desk at home, or at work
- Spill-proof: This durable keyboard features a spill-resistant design (1), anti-fade keys and sturdy tilt legs with adjustable height, meaning this keyboard is built to last
- Plastic parts in K120 include 51% certified post-consumer recycled plastic*
const password = page.getByLabel('Password');
await password.fill('secret');
await password.press('Enter');
You can also press Enter on a submit control:
await page.getByText('Submit').press('Enter');
What happens next is determined by the page. Native HTML submission, client-side validation, a framework handler, or an application-specific shortcut may all respond to the key. Playwright sends the event; it does not decide whether the page should navigate or which handler should run.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
If your test depends on navigation, combine the key action with an assertion that waits for the destination or a distinctive result state:
await password.press('Enter');
await expect(page).toHaveURL(/account/);
For an application that updates in place, assert the resulting message, panel, or other page state instead of waiting for a URL change.
Choosing a reliable locator
Pressing the right key is only useful if it reaches the right element. Prefer locators that describe what a user sees or what the control means:
- Role and name:
getByRole('textbox', { name: /search/i })communicates the control’s purpose. - Associated label:
getByLabel('Password')is appropriate for a labelled input. - Placeholder or other stable locator: useful when the page exposes no accessible name, provided the value is stable.
Before pressing, confirm that the locator resolves to the intended, visible, actionable element. If a page contains several textboxes, narrow the locator by name rather than relying on whichever match happens to be first.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →When to use page.keyboard.press()
The page-level alternative is:
await page.keyboard.press('Enter');
This sends Enter to the element that currently has focus. It is appropriate for a global keyboard shortcut or for a flow in which the test deliberately established focus in an earlier step. It is less explicit for ordinary form interactions because a later focus change can redirect the key.
Rank #3
- 【Large Print Keyboard】- 4X larger than standard keyboard fonts, clear and easy to find, and can really help those who have trouble seeing keyboards. Perfect for elderly, the visually impaired, schools, special needs departments and libraries, etc
- 【White LED Backlight】- Bright and evenly distributed backlit keys, easy typing in lower light environment. Ideal for studio work, office. Backlit can choose to turn on/off and adjust brightness.
- 【Full Size & Ergonomics Design】- Unfold the feet at back of the keyboard to reduce hand fatigue and enjoy long hours of playing. Full QWERTY English (US) 104 key keyboard layout with numeric keypad, Large Print keys provides superior comfort without forcing you to relearn how to type.
- 【Plug and Play & Wide Compatibility】 - This USB keyboard takes away the hassle of power charging or swapping out batteries and is easy to setup. No drivers required.Compatible with Windows 2000/XP/7/8/10, Vista,Raspberry Pi 3/4, Mac OS(Note: Multimedia keys may not fully compatible with Mac, OS System).Works with your PC, laptop.
- 【Spill-proof】- This durable keyboard features a spill-resistant design. So you don't have to worry about spilling coffee and water. Enjoy Keys life of more than 5000W times.
Playwright documents Keyboard.press() as a shortcut for a key-down followed by a key-up. In most cases, use Locator.press() instead, because the locator both identifies and focuses the target.
Key names and modifier combinations
Use Playwright’s logical key names rather than browser-specific text:
| Purpose | Example | When to use it |
|---|---|---|
| Enter | Enter |
Submit a field, activate a focused control, or invoke the page’s Enter handler. |
| Control shortcut | Control+Enter |
Applications that require Ctrl+Enter. |
| macOS shortcut | Meta+Enter |
Applications that specifically require Command+Enter. |
| Cross-platform shortcut | ControlOrMeta+Enter |
Use Control on Windows/Linux and Meta on macOS. |
| Other logical keys | Tab, Escape, ArrowDown, Home, F1–F12 |
Other keyboard interactions using the same press API. |
For example:
await page.getByRole('textbox').press('Control+Enter');
await page.getByRole('textbox').press('Meta+Enter');
Do not add a modifier unless the page’s shortcut actually requires one. A plain Enter and a modified Enter can be handled by different application code.
Recommended Free Tools
Fill text before pressing Enter
For normal input, call fill() and then press('Enter'):
const field = page.getByLabel('Query');
await field.fill('hello');
await field.press('Enter');
fill() is generally the right choice for tests because it sets the field value efficiently. Some applications attach behavior to every character event, such as a custom autocomplete or a masked input. In that case, use pressSequentially():
const field = page.getByLabel('Query');
await field.pressSequentially('hello', { delay: 50 });
await field.press('Enter');
Use sequential typing only when the page needs character-by-character keyboard handling; otherwise it adds time without improving the test.
Rank #4
- Durable and Reliable: This USB keyboard features a curved space bar, spill-resistant design (2), durable keys that can withstand 10 million keystrokes, and sturdy, adjustable tilt legs
- Comfortable, Familiar Typing: You’ll enjoy a comfortable and familiar typing experience thanks to the deep-profile keys and standard layout with full-size F-keys and number pad
- Full-size Sculpted Mouse: The high-definition optical USB mouse puts comfort and control in your hands with smooth, accurate tracking and an ambidextrous shape that feels good hour after hour
- Simple Set-Up: Simply plug the keyboard and mouse into the USB ports on your desktop, laptop, or netbook and you're ready to work; compatible with Windows 7, 8, 10 or later
- Clear and Convenient: The bold, bright white and long-lasting characters make the keys on this PC or laptop keyboard easy to read and extra durable
Why Enter may not trigger the expected action
The key went to the wrong element
A page-level press depends on current focus. If focus moved to a different control, the event may be ignored or handled elsewhere. Press Enter through the locator for the intended field or button.
The key name is incorrect
Use the exact logical name Enter. Check capitalization and include the required modifier, such as Control+Enter, when the application defines a shortcut rather than a plain Enter action.
The locator does not identify the intended control
Review the role, accessible name, label, and any matching elements. A broad textbox locator can target the wrong field when a page has a search box, filter box, and hidden form controls.
The page needs real typing events
If the application reacts to each character rather than only the final value, replace fill() with pressSequentially(). Keep the final Enter press on the same locator.
The action succeeded but the assertion ran too soon
When Enter starts navigation, assert the resulting URL or page state with Playwright’s waiting assertions. When the page updates without navigation, wait through an assertion for the visible result rather than checking immediately after the key event.
Enter causes validation instead of submission
That behavior can be correct for the page. Inspect the form’s required fields and validation state, then assert the error message if validation is the expected result. If submission should occur, fill the required fields before pressing Enter.
Best Value
- A plug-and-play USB connection with Low-profile keys give you a quiet, comfortable typing experience
- Simple Wired USB Connection,You will enjoy a comfortable and quiet typing experience
- The keyboard for business and office working is the budget-friendly keyboard that is built for longer use
- Low profile keys for a more comfortable and quiet keystroke, desktop-centric design, splash resistant
Patterns for common controls
Search field
const search = page.getByRole('textbox', { name: /search/i });
await search.fill('playwright');
await search.press('Enter');
await expect(page).toHaveURL(/results/);
Password field
const password = page.getByLabel('Password');
await password.fill('secret');
await password.press('Enter');
await expect(page).toHaveURL(/account/);
Submit button
const submit = page.getByText('Submit');
await submit.press('Enter');
Use a role-based button locator when the page exposes one; the text example above mirrors Playwright’s documented pattern for pressing Enter on a submit element.
Test design, reliability and speed
- Keep the key scoped: a locator-scoped action documents the intended recipient and reduces accidental focus dependence.
- Use semantic locators: role and label locators are easier to understand when the interface changes.
- Use the shortest input method that matches the UI: choose
fill()for ordinary fields andpressSequentially()only for character-sensitive widgets. - Assert an outcome: a successful key dispatch is not the same as a successful form submission. Check the URL, confirmation, validation message, or updated content that matters to the user.
- Match the shortcut exactly: plain Enter, Control+Enter, and Meta+Enter can represent separate application commands.
Or skip the browser setup
If your goal is to capture the page after a Playwright flow, ScreenshotNeo can return a screenshot or PDF with one HTTP request. It is a capture service, not a replacement for Playwright’s keyboard events, so use Playwright when you must interact with the form and ScreenshotNeo when you need a clean image of the resulting page.
Here is the one-call cURL example; the ScreenshotNeo documentation covers the request options:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minutecurl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan. Create a free ScreenshotNeo account to get started.
Frequently asked questions
Can ScreenshotNeo press Enter on a page?
No. ScreenshotNeo captures pages; it does not replace Playwright’s interaction APIs. Run the keyboard action in Playwright, then capture the resulting URL with ScreenshotNeo if you need an image or PDF.
Should a keyboard test assert the key event itself?
Usually, assert the user-visible consequence instead: the destination URL, successful result, or validation state. That verifies the behavior the user depends on rather than only confirming that a key was dispatched.
Frequently Asked Questions
Can ScreenshotNeo press Enter on a page?
No. ScreenshotNeo captures pages; it does not replace Playwright’s interaction APIs. Run the keyboard action in Playwright, then capture the resulting URL with ScreenshotNeo if you need an image or PDF.
Should a keyboard test assert the key event itself?
Usually, assert the user-visible consequence instead: the destination URL, successful result, or validation state. That verifies the behavior the user depends on rather than only confirming that a key was dispatched.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

