casperjs传递参数进行评估失败 [英] casperjs passing params to evaluate fails

查看:52
本文介绍了casperjs传递参数进行评估失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

casper.then(function(){
 phone_number   = '7wqeqwe6';
 phone_password = 'Teqweqweqw34';

});



casper.thenEvaluate(function(phone,password) {

document.querySelector('input#myTMobile-phone').setAttribute('value',phone);
document.querySelector('input#myTMobile-password').setAttribute('value',password);

//  document.querySelector('form').submit();
}, { 

phone    : phone_number,
password : phone_password

});

这会把我扔掉


string(307) [37; 41; 1mFAIL [0m ReferenceError:找不到变量:phone_number

string(307) "[37;41;1mFAIL[0m ReferenceError: Can't find variable: phone_number

推荐答案

尝试类似这样的方法:

var phone_number = '7wqeqwe6',
    phone_password = 'Teqweqweqw34';

casper.start('http://…');

casper.thenEvaluate(function(phone, password) {
    document.querySelector('input#myTMobile-phone').setAttribute('value', phone);
    document.querySelector('input#myTMobile-password').setAttribute('value', password);
    //  document.querySelector('form').submit();
}, {
    phone: phone_number,
    password: phone_password
});

注释:


  1. 很酷的有关javascript作用域的链接

  2. 填写表格?有一个 API

  1. a cool link on javascript scoping
  2. filling forms? there's an API for that

这篇关于casperjs传递参数进行评估失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆