Selenium “keypress” command to press enter key with ASCII key codes

Last updated on October 8th, 2025 at 11:37 am

Using “keypress” command in selenium
“keypress” command in selenium is very useful when you want to press keyboard keys like “Enter” key, “Up-Down arrows” key, “Backspace” key, “Shift” key, etc.. “keypress” command works like user pressing and then releasing that key. You need to provide targeted element locator (Where you want to press and

release key) in to target column of “keypress” command and ASCII value of keyboard key in value column.

Use of “keyPressAndWait” command in selenium
“keyPressAndWait” command will press specified key on targeted element and then it will wait for completing page loading. We can use “keyPressAndWait” command where page is reloading after pressing key. See bellow examples for how to press enter key using “keypress” command.
New Test
Command Target Value
open http://www.wikipedia.org/
type xpath=//input[@type=’search’] Selenium IDE
keyPress xpath=//input[@type=’search’] 13
verifyTextPresent seleniumhq.org
In above example, “keyPress” command will press and release “Enter” key of key board. Here, “13” is ASCII value of “Enter” Key. So in this case, selenium will works like user is typing “Selenium IDE” in search text box and then pressing “Enter” key of keyboard. You can use any key’s ASCII value as per your requirement. In above example, “verifyTextPresent” will becomes fail because selenium will execute next “verifyTextPresent” command immediately after “keyPress” command so it can not find targeted text “seleniumhq.org” during page loading.
In such cases you need to use “keyPressAndWait” command so it will press “Enter” key and then wait for page to load completely.  In bellow example, “verifyTextPresent” will becomes pass.
New Test
Command Target Value
open http://www.wikipedia.org/
type xpath=//input[@type=’search’] Selenium IDE
keyPressAndWait xpath=//input[@type=’search’] 13
verifyTextPresent seleniumhq.org
author avatar
Aravind
Hi, I’m Aravind — a seasoned Automation Test Engineer with over 17 years of hands-on experience in the software testing industry. I specialize in tech troubleshooting and tools like Selenium, Playwright, Appium, JMeter, and Excel automation. Through this blog, I share practical tutorials, expert tips, and real-world insights to help testers and developers improve their automation skills.In addition to software testing, I also explore tech trends and user-focused topics, including Snapchat guides, codeless test automation, and more.
Stay Updated with New Articles
Get the latest tutorials and insights delivered to your inbox.

One thought on “Selenium “keypress” command to press enter key with ASCII key codes

Leave a Reply

Your email address will not be published. Required fields are marked *