【发布时间】:2017-01-16 05:47:36
【问题描述】:
我正在尝试编写一个在 https://frontier.com/login 登录的 CasperJS 脚本。
我遇到了麻烦,因为:
它使用 AngularJS,所以我似乎无法访问和更改其范围内的值(例如
ng-model='login.loginId')。直接在元素上设置值没有任何效果。输入字段未用表单元素包装,因此无法使用通常的
fillSelectors()和 CasperJScasper.exists('input#fid-login-inline-username')返回 true,但是,casper.sendKeys('input#fid-login-inline-username', 'blah')给出错误提示[error] [remote] mouseEvent(): Couldn't find any element matching 'input#fid-login-inline-username' selector
要使用的字段是:
input#fid-login-inline-usernameinput#fid-login-inline-password-
div.login-form-container button.btn-primary- 对于click()
那么,如何将 casper 中的两个输入字段编辑到角度范围内?
这是我尝试过的一个示例:
casper.start('https://frontier.com/login', function() {
this.echo('waiting for password input field');
this.waitForSelector("input#fid-login-inline-password");
});
casper.then(function() {
if (this.exists('input#fid-login-inline-username')) {
this.echo('username input exists');
}
if (this.exists('input#fid-login-inline-password')) {
this.echo('password input exists');
}
this.echo('filling in username and password');
// these fields are not in a form element, so, use sendKeys to enter text...
// the above echoes print the fields exist, and then these sendKeys
// operations emit an error that the fields don't exist.
this.sendKeys('input#fid-login-inline-username', 'some@email.com');
this.sendKeys('input#fid-login-inline-password', 'some-password');
});
casper.then(function() {
this.echo('clicking login button');
this.click('div.login-form-container button.btn-primary');
});
【问题讨论】: