【问题标题】:casperjs command line argument failurecasperjs命令行参数失败
【发布时间】:2019-03-12 03:28:29
【问题描述】:

这对每个人来说可能都很明显,但我正在学习,对我来说不是:)

在 sendkeys 函数中,如果我通过命令行指定 pid,它会失败。如果我在文件中指定它,它可以工作。它确实被设置了,因为 echo 对这两种方法都有效。当我说失败时,我的意思是 1910193 没有出现在屏幕截图的框中。为什么?

我的命令

rm screenshot.jpg; casperjs mytest.js --pid="1910193"

我的代码

var casper = require('casper').create()
var x = require('casper').select

// obviously, these are not both used at the same time
var pid = '1910193'; // specified in file
var pid = casper.cli.get("pid") // specified on cmdline

casper.echo(pid); // works with both specification methods

casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
casper.start('https://myurl.net');
casper.then(function () {
   this.sendKeys('#Account', pid);
   console.log('searching.....');
   casper.capture('screenshot.jpg')
});

casper.run();

【问题讨论】:

    标签: command-line casperjs options


    【解决方案1】:

    这是因为 sendKeys 只能处理字符串。 pid 通过命令行作为 int 传递。我将它类型转换为一个字符串,然后它按预期工作。

    var pid = String(casper.cli.get("pid"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      相关资源
      最近更新 更多