Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 3 weeks ago
Can't fire browser behaviours with keyevent
I am using PhantomJS 2.1.1 to send the Enter keycode to a page on a client-side site built with VAADIN for testing. The page is never submitted. When I added the listener to output what the key code was, it showed 0 instead of 13
Am I doing something wrong?
document.getElementsByTagName("input")[1].focus();
document.getElementsByTagName("input")[1].value = "123456";
document.addEventListener('keydown', function(e){
console.log("key pressed was: " + e.keyCode);
});
//SEND RETURN KEY TO PAGE
var ev = document.createEvent('KeyboardEvent');
ev.initKeyboardEvent( 'keydown', true, true, window, false, false, false, false, 13, 0);
document.getElementsByTagName("input")[1].dispatchEvent(ev);
The PhantomJS SendEvent doesn't work either on the page. It too returns 0
page.sendEvent('keypress', page.event.key.ENTER);
There is no form tag to .submit(). In a standard Firefox application using ScratchPad, I CAN use the dispatchEvent and it works fine.
Last updated on
You cannot reply to this thread.