Press special character in Browser Playback Tool

RobinRobin Posts: 1

In the Browser Playback Tool there is an user action for KeyUp, KeyDown and Type. However all of these require a Text Input. How can I use there for a charactler like the Escape key for example.


  • tonytony Posts: 23

    To simulate keys that do not produce characters you will need to use the Execute JavaScript functionality. Please note that this may not work in all cases, as browsers often have auxiliary behavior attached to these non-character keys (such as dropping focus) that is not emulated through JavaScript. This will simply trigger any code listening for an event on the specified key.

    Below is an example of how to trigger a "keydown" with the "Escape" key. You can modify this code to trigger different events with different keys by changing "keycode" and "eventType."

    function typeSpecialCharacter(element) {
        var keycode = 27; // the escape keycode
        var eventType = "keydown";
        var evt;
        var win = element.ownerDocument.defaultView;
        if (win.KeyEvent) {
           evt = element.ownerDocument.createEvent('KeyEvents');
           evt.initKeyEvent(eventType, true, true, win, false, false, false, false, keycode, keycode);
        } else {
           evt = element.ownerDocument.createEvent('UIEvents');
           evt.initUIEvent(eventType, true, true, win, 1);
           evt.keyCode = keycode;
Sign In or Register to comment.