Question

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

Was it helpful?

Solution

This Java code works for me:

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

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

OTHER TIPS

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

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top