Simulating Keypress Events in Selenium IDE
Since version 2.3.0, Selenium IDE supports keyboard keypress events. We can simulate Selenium IDE keypress events using newly introduced sendKeys command. Keypress events can be utilized in WebDriver Playback as well. All in all, it’s a very useful addition in Selenium IDE. Therefore in this tutorial, we will discuss about different options available in Selenium IDE to handle keyboard keypress events.
Let’s see how to use sendKeys in Selenium IDE. sendKeys command takes locator and value parameters just like any other Selenium IDE commands. To define a keyboard key, you just have to prefix its value with ‘KEY_’ text and write it as variable(Eg. using ${ }). For example, below command hits Enter key on button called ‘login’.
Navigation Keys:
- KEY_LEFT (Navigation Left)
- KEY_UP (Navigation Up)
- KEY_RIGHT (Navigation Right)
- KEY_DOWN (Navigation Down)
- KEY_PGUP / KEY_PAGE_UP (Page up)
- KEY_PGDN / KEY_PAGE_DOWN (Page down)
- KEY_END (End)
- KEY_HOME (Home)
- KEY_F1 to KEY_12 (Function keys from F1 to F12)
- KEY_ALT (Alt)
- KEY_CONTROL / KEY_CTRL (Ctrl)
- KEY_META / KEY_COMMAND (Command)
- KEY_SHIFT (Shift)
- KEY_NUMPAD0 / KEY_N0 to KEY_NUMPAD9 / KEY_N9 (Number keys from 1 to 9)
- KEY_ADD / KEY_NUM_PLUS (Plus)
- KEY_DECIMAL/ KEY_NUM_PERIOD (Period)
- KEY_DIVIDE/ KEY_NUM_DIVISION (Division)
- KEY_MULTIPLY/ KEY_NUM_MULTIPLY (Multiply)
- KEY_SEPARATOR/ KEY_SEP (Separator)
- KEY_SUBTRACT/ KEY_NUM_MINUS (Minus)
- KEY_BKSP / KEY_BACKSPACE (Backspace)
- KEY_DEL / KEY_DELETE (Delete)
- KEY_ENTER (Enter)
- KEY_EQUALS (Equals)
- KEY_ESC / KEY_ESCAPE (Escape)
- KEY_INS / KEY_INSERT (Insert)
- KEY_PAUSE (Pause)
- KEY_SEMICOLON (Semi-colon)
- KEY_SPACE (Space)
- KEY_TAB (Tab)
We hope you would find the above post illustrating Selenium IDE keypress events useful. Let us know your views in comments.
Selenium IDE JavaScript and Command Parameters
The example below shows you how a JavaScript snippet can be used to perform a simple numerical calculation.
Command | Target | Value |
store | 10 | Number1 |
store | 20 | Number2 |
storeEval | parseInt(storedVars['Number1'])+parseInt(storedVars['Number2']) | sumResult |
echo | ${sumResult} |
- [info] Executing: |store | 10 | Number1 |
- [info] Executing: |store | 20 | Number2 |
- [info] Executing: |storeEval | parseInt(storedVars['Number1'])+parseInt(storedVars['Number2']) | sumResult |
- [info] script is: parseInt(storedVars['Number1'])+parseInt(storedVars['Number2'])
- [info] Executing: |echo | ${sumResult} | |
- [info] echo: 30
JavaScript Usage with Non-Script Parameters
JavaScript can also be used to help generate values for parameters, even when the parameter is not specified to be of type script. However, in this case, special syntax is required–the JavaScript snippet must be enclosed inside curly braces and preceded by the label JavaScript.Command | Target | Value |
store | 10 | Number1 |
store | 20 | Number2 |
echo | javascript{parseInt(storedVars['Number1'])+parseInt(storedVars['Number2'])} |
Комментариев нет:
Отправить комментарий