如何通过 phantomjs 设置 Vue 输入?

How set Vue inputs via phantomjs?

这样的代码:

document.getElementById('email').value = 'login';
document.getElementById('password').value = 'pwd';
document.getElementById('button').click();

不起作用,因为 Vue 使用 v-model 值而不是 value 属性。有没有办法通过 phantomjs 中的 javascript 更改输入和模型值?

备注

  1. 设置属性v-model对于那些输入没有解决 问题。

  2. 无法使用 CSP-compliant-build,因为我无法从源代码重建项目。

  3. 也不能使用 chrome 的任何扩展,因为页面是通过 phantomjs 呈现的

PhantomJS supports sending "real" keypress 事件到页面。您需要先关注必要的字段,然后输入:

page.evaluate(function(){
    document.getElementById("#email").focus();
});
page.sendEvent('keypress', 'login');

page.evaluate(function(){
    document.getElementById("#password").focus();
});
page.sendEvent('keypress', 'pwd');

page.sendEvent('keypress', page.event.key.Enter);