我正在使用waitFor()
。代码如下:
casper.waitFor(function check() {
return this.evaluate(function() {
return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
});
}, function then() {
console.log('Done');
});
将此作为控制台输出
Wait timeout of 5000ms expired, exiting.
如何增加超时?
编辑:我已将代码更改为
casper.waitFor(function check() {
return this.evaluate(function() {
return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
});
}, function then() {
console.log('Done');
},10000);
它给了我以下错误:
CasperError: Invalid timeout function, exiting.
C:/filename:1720 in _check
答案 0 :(得分:58)
使用它来增加每个wait()函数的超时:casper.options.waitTimeout = 20000;
(20秒)
答案 1 :(得分:27)
如上所述here,
签名是
waitFor(Function testFx[, Function then, Function onTimeout, Number timeout])
因此,有一个额外的参数来指定超时。
casper.waitFor(function check() {
//...
});
}, function then() {
//...
}, function timeout() {
//...
}, TIMEOUT_IN_MS);
答案 2 :(得分:1)
如果要在保留默认错误消息的同时增加超时,请将null
作为第三个参数传递,并将等待的毫秒数作为第四个参数:
casper.waitFor(function check() {
return this.evaluate(function() {
return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
});
}, function then() {
console.log('Done');
}, null, 10000);