如何增加CasperJS中的超时

use*_*794 31 javascript phantomjs casperjs

我在用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');
});
Run Code Online (Sandbox Code Playgroud)

我把它作为控制台输出

Wait timeout of 5000ms expired, exiting.
Run Code Online (Sandbox Code Playgroud)

如何增加超时?

编辑:我已将代码更改为

 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);
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误:

CasperError: Invalid timeout function, exiting.
    C:/filename:1720 in _check
Run Code Online (Sandbox Code Playgroud)

Fan*_*nch 58

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


Cyb*_*axs 27

至于说在这里,

签名是

waitFor(Function testFx[, Function then, Function onTimeout, Number timeout])
Run Code Online (Sandbox Code Playgroud)

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

casper.waitFor(function check() {
    //...
    });
}, function then() {
     //...
}, function timeout() { 
//...
}, TIMEOUT_IN_MS);
Run Code Online (Sandbox Code Playgroud)

  • 您还可以设置一个选项以增加超时.这将是所有定时功能的默认设置.请参阅以下链接:[link](http://docs.casperjs.org/en/latest/modules/casper.html#timeout) (5认同)