I have an ExtJs text field on a page. I am filling it with some value in casper.js, which works fine.
Then I want to focus this field and press the Enter key, as there is no <form>
around it to submit.
What I tried was:
casper.then(function() {
// the text field is filled with the string
this.sendKeys('#searchfield', 'some text');
this.evaluate(function() {
// this does not put the field in focus
document.querySelector('#searchfield').focus();
// so 'pressing' enter has no effect at all
var evt = document.createEvent('KeyboardEvent');
evt.initKeyboardEvent('keypress', true, true, window, 0, 0, 0, 0, 0, 13);
document.dispatchEvent(evt);
});
});
Do you have any idea how to accomplish this?