Use Selenium Python’s ActionChains to press Enter on the element that currently has keyboard focus, without passing a WebElement to the key action:
from selenium.webdriver import ActionChains, Keys
ActionChains(driver).send_keys(Keys.ENTER).perform()
The key goes to the focused page element; Selenium does not choose an arbitrary input for you. If the intended control does not already have focus, focus it first.
Send Enter to the currently focused element
ActionChains.send_keys() sends keys to the current focused element. The pattern is:
from selenium.webdriver import ActionChains, Keys
ActionChains(driver).send_keys(Keys.ENTER).perform()
This is useful when the page has already placed focus on the right control, or a preceding action has done so, and you do not want to pass a WebElement to the Enter action. The API documentation for Selenium Python 4.50.0 describes this focused-element behavior in the ActionChains API.
Recommended Free Tools
#1 Best Overall
Make sure the intended control has focus
The recipient is determined by page focus. If you need to establish it, locate and focus the control first, then send Enter through ActionChains:
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By
search_box = driver.find_element(By.NAME, "q")
search_box.click()
search_box.send_keys("Selenium")
ActionChains(driver).send_keys(Keys.ENTER).perform()
Here, the input is located to click it and type a query; the final Enter action does not take a WebElement argument. If a prior page interaction already focused the correct control, omit the locating and clicking steps. Whether Enter submits a form or triggers another response depends on the page’s own keyboard handling.
Rank #2
Choose between ActionChains and element send_keys
| Situation | Use | Example |
|---|---|---|
| The intended control has focus and you do not want to pass it to the key action | Focused-element ActionChains | ActionChains(driver).send_keys(Keys.ENTER).perform() |
| You can locate the intended control and want to send the key directly to it | Element-directed send_keys | elem.send_keys(Keys.RETURN) |
Selenium’s Python bindings guide demonstrates sending Keys.RETURN to a located element. The WebDriver element interactions guide describes element-directed key input for text fields and keyboard-interactable elements. Use the element-directed form when the target is known; use the ActionChains form when the correct page control already has focus and you do not pass it to that action.
Or skip the browser setup
If your goal is to capture a page rather than exercise its keyboard behavior, ScreenshotNeo can return a screenshot with one request. For example, use this cURL request to capture stripe.com:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Quick Recap
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for request options. ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; these steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. An MCP server offers take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo, or sign up for free.
Troubleshoot Enter not reaching the expected control
- Nothing happens: Check which page control has focus. Click or otherwise focus the intended control before sending Enter.
- The wrong control receives Enter: Focus another control explicitly, or locate the target and use its
send_keys()method directly. - You expect a browser shortcut: This pattern sends page keyboard input to the focused element. The cited Selenium documentation does not establish it as a reliable way to invoke browser-chrome shortcuts.
- You used JavaScript to imitate a key press: Executing JavaScript is a different operation from sending keyboard input; it does not establish that the page received an Enter key event. Use the WebDriver keyboard action when the goal is to send Enter.
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.




