In part 1, we saw how to use the special keys in the sendKeys command in Selenium IDE starting in v2.3.0. Selenium IDE v2.4.0 shortened some key names. This post serves as a quick reference and provides the full list of all supported special keys and some notes. If there are two options given, you can use either one of them.
Using the Special Keys
The special keys are implemented as stored variables. You use them similar to the way you use the special keys. i.e. enclose them in ${}, e.g.:
${KEY_ENTER}
If you want to use more than one special keys, each needs to be enclosed in ${}, e.g.:
${KEY_LEFT}${KEY_BKSP}
You can mix and match regular text and special keys as you like. e.g.:
Everybody loves chese${KEY_LEFT}${KEY_LEFT}e
Keep in mind that you should not create stored variables with the same names as special keys in your tests. It is recommended that you do not create any stored variables that begin with the KEY_ prefix.
Using the Modifier Keys
The first occurance of a modifier key presses them and the second one releases it. If a modifier key is used more than twice, then, it is easier to think that the odd times are presses and the even times are releases. All modifier keys are released at the end of the sendKeys command and will not affect the subsequent sendKeys command.
Supported Modifier Keys
- KEY_ALT
- KEY_CONTROL / KEY_CTRL
- KEY_META / KEY_COMMAND
- KEY_SHIFT
Supported Common Keys
- KEY_BKSP / KEY_BACKSPACE
- KEY_DEL / KEY_DELETE
- KEY_ENTER
- KEY_EQUALS
- KEY_ESC / KEY_ESCAPE
- KEY_INS / KEY_INSERT
- KEY_PAUSE
- KEY_SEMICOLON
- KEY_SPACE
- KEY_TAB
Supported Navigation Keys
- KEY_LEFT
- KEY_UP
- KEY_RIGHT
- KEY_DOWN
- KEY_PGUP / KEY_PAGE_UP
- KEY_PGDN / KEY_PAGE_DOWN
- KEY_END
- KEY_HOME
Supported Number Pad Keys
- KEY_NUMPAD0 / KEY_N0
- KEY_NUMPAD1 / KEY_N1
- KEY_NUMPAD2 / KEY_N2
- KEY_NUMPAD3 / KEY_N3
- KEY_NUMPAD4 / KEY_N4
- KEY_NUMPAD5 / KEY_N5
- KEY_NUMPAD6 / KEY_N6
- KEY_NUMPAD7 / KEY_N7
- KEY_NUMPAD8 / KEY_N8
- KEY_NUMPAD9 / KEY_N9
- KEY_ADD / KEY_NUM_PLUS
- KEY_DECIMAL/ KEY_NUM_PERIOD
- KEY_DIVIDE/ KEY_NUM_DIVISION
- KEY_MULTIPLY/ KEY_NUM_MULTIPLY
- KEY_SEPARATOR/ KEY_SEP
- KEY_SUBTRACT/ KEY_NUM_MINUS
Supported Function Keys
- KEY_F1
- KEY_F2
- KEY_F3
- KEY_F4
- KEY_F5
- KEY_F6
- KEY_F7
- KEY_F8
- KEY_F9
- KEY_F10
- KEY_F11
- KEY_F12
The Future of Special Keys
While I think that this feature is done, I have a couple of more ideas that may make it even better. The first idea is to introduce shorter forms for commonly used keys. The second idea is to provide a way to specify the number of times to press a key. Without any feedback of how many people actually use this, it will be difficult to prioritise these improvements. So, leave a comment, send me a tweet, get in touch!
Pingback: Using Special Keys in Selenium IDE – Part 1 | Really Simple Thoughts of a Perpetual Learner
Great feature, thank you! I would love a way to be able to press a key multiple times in a single command.
Ed
Wonderful; thank you. Is there a way we can do a ‘select all’ (eg: ctrlA)? That could help in clearing text boxes and search fields.
Hi Divya,
Yes. You can sendKeys with ${KEY_CTRL}A
Cheers,
Samit Badle
Hello,
At first, thank you for that !
The Future of Special Keys : to provide a way to specify the number of times to press a key.
Is this idea always on your agenda ?
It would help me a lot in context of lists
Hi Jean-Pierre,
Yes it is. I have a solution and it may even make it in time for the next release of Selenium IDE.
Cheers,
Samit