9

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

some_other_guy
  • 3,364
  • 4
  • 37
  • 55
Tomo
  • 3,431
  • 5
  • 25
  • 28

5 Answers5

10

This Java code works for me:

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

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

noah
  • 21,289
  • 17
  • 64
  • 88
  • what about situation when i got error message and there isn't any id about that button? Can i somehow just press enter by selenium? – deadfish Jul 22 '11 at 09:49
5

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

0

you can use Webelement.sendkeys(Keys.Enter);

user1710861
  • 413
  • 6
  • 9
0

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;" ?

Scott Gowell
  • 485
  • 1
  • 5
  • 14
0

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
  • 8,038
  • 6
  • 38
  • 53