1

CasperJS を使用していくつかのフォーム (入力フィールド、選択ボックスなど) に入力しています。jquery をスクリプトに挿入しましたが、残りの部分を機能させる方法がわかりません。

私は基本的に、ページ上の単一の要素を「見つけて」、この中のタグを見つけて値を変更しようとしています。これが変更されたら、「add_phone」という html 名を持つ送信ボタンをクリックします。

これが私がこれまでに持っているものです-私はPhantomJS v1.9.1でCasperJS 1.1.0-DEVの最新バージョンを使用していることに注意してください

これを実行すると、次のエラーが返されます。

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

コード:

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();
4

1 に答える 1

4

thisどの関数からもundefinedcasperjsにあります

試してくださいcasper.then

casper.start(url);
casper.then(function() {
  var deviceValue = this.evaluate(function() {
     return $('table').find('select').val();
  });
  this.echo(deviceValue);
});
于 2013-07-31T08:55:48.673 に答える