31

我正在使用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
4

3 回答 3

58

使用它来增加每个 wait() 函数的超时时间:casper.options.waitTimeout = 20000; (20 秒)

于 2014-05-20T12:12:56.983 回答
27

正如这里所说,

签名是

waitFor(Function testFx[, Function then, Function onTimeout, Number timeout])

因此,有一个额外的参数来指定超时。

casper.waitFor(function check() {
    //...
    });
}, function then() {
     //...
}, function timeout() { 
//...
}, TIMEOUT_IN_MS);
于 2013-08-13T10:29:06.953 回答
1

If you want to increase timeout while leaving the default error message, pass null as the third argument and number of milliseconds to wait as the fourth argument:

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);
于 2015-04-16T13:28:50.967 回答