SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Selenium "keypress" command to press enter key with ASCII key codes

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
CommandTargetValue
openhttp://www.wikipedia.org/
typexpath=//input[@type='search']Selenium IDE
keyPressxpath=//input[@type='search']\13
verifyTextPresentseleniumhq.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
CommandTargetValue
openhttp://www.wikipedia.org/
typexpath=//input[@type='search']Selenium IDE
keyPressAndWaitxpath=//input[@type='search']\13
verifyTextPresentseleniumhq.org

2 comments:

  1. If you want to press enter key in selenium the read this: http://coding-issues.blogspot.com/2012/11/press-enter-key-in-selenium.html

    ReplyDelete