It looks like, you can't trigger the keypress
event using jQuery. There is a workaround using the underlying casper.page.sendEvent
function. Though it is necessary to focus on the element, where the keypress
will be triggered. In the following example I use the keepFocus
option of the sendKeys
function.
var casper = require('casper').create();
casper.start("https://duckduckgo.com/");
casper.then(function() {
this.sendKeys("#search_form_homepage input[name=q]", "casperjs", { keepFocus: true });
this.capture("typed.png");
this.page.sendEvent("keypress", this.page.event.key.Enter);
});
casper.waitForSelector("#links_wrapper");
casper.then(function() {
this.capture("searched.png");
});
casper.run();