【问题标题】:How to use global variables in casperjs?如何在 casperjs 中使用全局变量?
【发布时间】:2017-09-08 12:22:30
【问题描述】:

如何在 .then 中使用一些全局变量及其内容?

var casper = require('casper').create();
var globalVariable = "hello world";    
casper.start('http://163.172.110.7/be/get.php', function() {    
  var source = this.getPageContent();
  var json = JSON.parse(source);  
  console.log('step1:', globalVariable);

});
casper.then(function() {
    this.echo('step2', globalVariable);
    casper.exit();
});
casper.run();

Step1 : 给我“hello world”

第二步:给我“”

我也试过用 casper.globalVariable

【问题讨论】:

    标签: casperjs


    【解决方案1】:

    this.echo() 得到 2 个参数,它只输出第一个。 console.log() 连接其所有参数:

    var casper = require('casper').create();
    var globalVariable = "hello world";
    casper.start('http://163.172.110.7/be/get.php', function() {
      var source = this.getPageContent();
      var json = JSON.parse(source);
      console.log('step1:', globalVariable);
    });
    casper.then(function() {
      this.echo('step2', globalVariable);
      console.log('step2:', globalVariable);
      casper.exit();
    });
    casper.run();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-14
      • 2021-05-23
      • 2018-08-26
      • 2012-12-31
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多