我正在尝试提交基于Javascript的表单。首先,我单击该元素,然后删除该字段中的任何文本,然后输入我想要的文本。最后,我想模拟Enter / Return按钮来提交字段。 (没有'提交'按钮,必须按Enter / Return或Tab键提交。)这是我到目前为止所做的:
//This works
casper.click(x('//span[@data-title="abd"]'), {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Backspace, {keepFocus: true});
casper.sendKeys(x('//span[@data-title="abd"]'), "efg", {keepFocus: true});
//This doesn't
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Return);
一直工作到最后的Return / Enter按键。该网站只是没有注册。知道为什么吗?
我也试过这些;这些都不起作用:
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Enter);
casper.sendKeys(x('//span[@data-title="abd"]'), casper.page.event.key.Tab);
casper.page.sendEvent('keypress', casper.page.event.key.Return);
casper.page.sendEvent('keypress', casper.page.event.key.Enter);
casper.page.sendEvent('keypress', casper.page.event.key.Tab);