質問

I am using CasperJS to fill out some forms (input fields, select boxes etc..) I have got jquery injected into the script but I am not sure how to get the rest of it working.

I am basically trying to 'find' the single element on the page and find the tag within this and change the value. Once this has been changed I want to click the submit button that has the html name of 'add_phone'.

Here is what I have so far - note I am using the latest version of CasperJS 1.1.0-DEV with PhantomJS v1.9.1

This when executed returns the following error:

TypeError: 'undefined' is not a function (evaluating 'this.evaluate(function() { 
   return $('table').find('select').val();
 });

Code:

var casper = require('casper').create({
  clientScripts: ['includes/jquery.min.js'],
  verbose: true,
  logLevel: 'debug',
  loadImages: false
});

 var url = 'http://www.simplysellular.com/displayphone.php?manufacturers=Apple&phones=iPhone+5+(ATT/GSM)+32GB&affiliates_id=14&affiliates_tracking_id=2072&utm_source=sellcell&utm_medium=web&utm_campaign=sellcell&condition_id=15';
 casper.start(url);

 var deviceValue = this.evaluate(function() {
 return $('table').find('select').val();
});

this.echo(deviceValue);

casper.exit();
役に立ちましたか?

解決

this out of any function is undefined in casperjs

Try casper.then:

casper.start(url);
casper.then(function() {
  var deviceValue = this.evaluate(function() {
     return $('table').find('select').val();
  });
  this.echo(deviceValue);
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top