I am trying to simulate pressing 'enter' with javascript for automation.
var script = document.createElement('script'); script.src = 'https://code.jquery.com/jquery-1.10.2.min.js'; script.type = 'text/javascript'; document.body.appendChild(script); var e = jQuery.Event("keypress"); e.which = 13;
This is the code used to configure the key event (I also tried keydown and keyup).
This does not work when searching on Google. If I type text and fire an event in the input field $("[name=q]").trigger(e) , nothing happens.
I use google to test the simulation of the "correct" event input. I hope to use js to automate the skype web client.
Does anyone know if it is possible to simulate an actual input key press using javascript? I saw that Selenide pressEnter() works, but it uses webdriver, so maybe this is not relevant.
I also tried running js event jQuery
var dispatchKeyboardEvent = function(target, initKeyboradEvent_args) { var e = document.createEvent("KeyboardEvents"); e.initKeyboardEvent.apply(e, Array.prototype.slice.call(arguments, 1)); target.dispatchEvent(e); }; dispatchKeyboardEvent($("[name=q]"), 'keypress', true, true, null, 'h', 13, '');
sidenote I know that a request can be sent by calling .submit () for an element, but this is not what I am after.
javascript jquery events
Bobbzorzen
source share