casperjs命令行参数失败

问题描述 投票:0回答:1

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

在sendkeys函数中,如果我通过命令行指定pid,则pid会失败。如果我在文件中指定它,它可以工作。它确实被设置,因为回声适用于这两种方法。当我说失败时,我的意思是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个回答
0
投票

这是因为sendKeys只能使用字符串。 pid通过命令行作为int传递。我将它转换为字符串然后按预期工作。

var pid = String(casper.cli.get("pid"));
© www.soinside.com 2019 - 2024. All rights reserved.