How to send EnterKey in Ajax TruClient

443 views
Skip to first unread message

Chimona Zana

unread,
Sep 18, 2013, 11:51:24 PM9/18/13
to LR-Loa...@googlegroups.com

After cilck save button , have ok dialog box. With programming process loadrunner cannot work

How to evaluate JavaScript send EnterKey ?


Thank you.

James Felton

unread,
Sep 29, 2013, 11:49:04 PM9/29/13
to LR-Loa...@googlegroups.com
Hi Chimona,

I can think of 2 ways to solve this issue.
The first and easiest is to do the following:
  1. On the page you want to "Press enter" on, Insert a "Generic Object Action" into your script
  2. Click the element on which you wish to preform the key press on
  3. In the "Step" section set the "Action" property to "Press Key"
  4. In the "Arguments" section the the "Key Name" property to "Enter"
The 2nd way will let you preform any keystroke on the page in general.

     Step 1: Insert an "Evaluate JS Function" block into your TruClient script
     Step 2: Copy & paste this code into the code editor (source: http://stackoverflow.com/questions/596481/simulate-javascript-key-events):

var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent"; 
keyboardEvent[initMethod](
                   "keydown", // event type : keydown, keyup, keypress
                    true, // bubbles
                    true, // cancelable
                    window, // viewArg: should be window
                    false, // ctrlKeyArg
                    false, // altKeyArg
                    false, // shiftKeyArg
                    false, // metaKeyArg
                    118, // keyCodeArg : unsigned long the virtual key code, else 0
                    0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);

Step 3: Find out what the keyCodeArg or charCodeArg is for the key you wish to press, (118 is F7).

Hope this helps,

James
Reply all
Reply to author
Forward
0 new messages