How to simulate pressing enter in html text input with Selenium?

Tomo picture Tomo · Sep 16, 2008 · Viewed 18.1k times · Source

In a web interface, I've got a text field. When user enters text and accepts with enter, application performs an action.

I wanted to test the behavior with Selenium. Unfortunately, invoking 'keypress' with chr(13) insert representation of the character into the field.

Is there a way other then submitting the form? I'd like to mimic intended user interaction, without any shortcuts...

Answer

noah picture noah · Sep 16, 2008

This Java code works for me:

selenium.keyDown(id, "\\13");

Notice the escape. You probably need something like chr(\13)