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
});
this throws me
string(307) "[37;41;1mFAIL[0m ReferenceError: Can't find variable: phone_number
Is there a way to pass params to evaluate method?
The other answers are pre 1.0. The preferred way is to pass along the arguments in line
Example
casper.evaluate(function(username, password) {
document.querySelector('#username').value = username;
document.querySelector('#password').value = password;
document.querySelector('#submit').click();
}, 'sheldon.cooper', 'b4z1ng4');
http://docs.casperjs.org/en/latest/modules/casper.html#evaluate
Try something like this:
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
});
Notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With