views:

4412

answers:

4

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...

A: 

Though I haven't tested this I imagine you can use "\r\n" appended to a string to simulate a new line. If not look for the languages equivalent to "Environment.NewLine;" ?

Penguinix
A: 

It's been a while since I've had to do this, but I seem to recall having to use a javascript snippet to execute the carrage return as opposed to using the Selenium keypress function.

Peter Bernier
+5  A: 

This Java code works for me:

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

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

noah
Quoting the quote. That does the trick!
Tomo
+1  A: 

I ended up using selenium.keyPress(id, "\\13");