这样的代码:
document.getElementById('email').value = 'login';
document.getElementById('password').value = 'pwd';
document.getElementById('button').click();
不起作用,因为 Vue 使用 v-model
值而不是 value
属性。有没有办法通过 phantomjs 中的 javascript 更改输入和模型值?
注释
为这些输入设置属性
v-model
不能解决 问题。无法使用
CSP-driven-build
,因为我无法从源代码重建项目。任何 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);
关于javascript - 如何通过 phantomjs 设置 Vue 输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45855220/