【发布时间】:2013-06-01 07:37:45
【问题描述】:
我在页面上有一个 ExtJs 文本字段。我在 casper.js 中填充了一些值,效果很好。
然后我想关注这个字段并按Enter键,因为它周围没有<form>可以提交。
我尝试的是:
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);
});
});
你知道如何完成这个吗?
【问题讨论】:
标签: javascript forms keypress casperjs extjs2