I need to Press space Key using JavaScript Inside a TextBox after typing the string. How can I do it inside vugen tool (Load runner) using eval js function? can anyone guide me?
I tried inside to evaluate javascript on the object but getting an error.
var e = new KeyboardEvent('keydown',{'keyCode':32,'which':32});
object.dispatchEvent(e);
I am using Eval Js on object function in the tool and paste this script.
ERROR:
No Error it is not clicking the space key inside text box.
I also tried this code
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
"initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keypress", // event type : keydown, keyup, keypress
true, // bubbles
true, // cancelable
window, // viewArg: should be window
false, // ctrlKeyArg
false, // altKeyArg
false, // shiftKeyArg
false, // metaKeyArg
32, // keyCodeArg : unsigned long the virtual key code, else
0 // charCodeArgs : unsigned long the Unicode character
associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);
For this also no Error but the code is not clicking space inside text box.
If you are using TruClient, you could add a eval JS step. TruClient support AUT.document and AUT.window to reference the current page of the application under test.
If you are using a eval JS step on Object, then the target element can be referenced with "object" in the code of the step.
The detail inforamtion can be found from here