0

我一直在尝试测试网页以查看功能是否有效。我尝试这样做的方法是将 getFormValues 的输出与功能确实有效的字符串进行比较。我写了以下任务来检查:

casper.then(function seeifsaveworked() {
    if (this.getFormValues('.tf-field-inner') === 'foobar') {
        this.echo("SUCCESS: The site description has been successfully changed, so the save did work", 'INFO');
    } else {
        this.echo("ERROR: The save attempt didn't work successfully, something is wrong with your connection or the page isn't functioning properly.", "ERROR");
        this.die();
    };
});

当我运行脚本时,我得到一个解析错误,因为该代码的某些内容在语法上不正确。我不知道为什么它不正确,以及是否有人可以解决语法错误以及我需要做些什么来完成绝对了不起的原始任务。

谢谢

4

1 回答 1

1

我认为不正确的语法是 else 语句后的分号可能是一个错误。

casper.then(function seeifsaveworked() {
    if (this.getFormValues('.tf-field-inner') === 'foobar') {
        this.echo("SUCCESS: The site description has been successfully changed, so the save did work", 'INFO');
    } else {
        this.echo("ERROR: The save attempt didn't work successfully, something is wrong with your connection or the page isn't functioning properly.", "ERROR");
        this.die();
    };  <----------- Remove this.
}); 

至于检查表格,casper 的文档显示了这一点:

casper.start('http://www.google.fr/', function() {
    this.fill('form', {q: 'plop'}, false);
    this.echo(this.getFormValues('form').q); // 'plop'
});

我认为您需要更改的是,当您访问表单值时,您需要指定要比较的字段并确保您选择了表单。

if(this.getFormValues('form#formid').name === 'foobar')...
于 2013-07-19T16:04:43.820 回答