gpt4 book ai didi

javascript - 如果 Nightmare waitTimeout超出,则调用函数

转载 作者:行者123 更新时间:2023-12-03 13:24:00 24 4
gpt4 key购买 nike

使用nightmareJS,如果超过了waitTimeout限制,有什么方法可以调用函数?现在它给了我一个 promise 被拒绝的警告

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: .wait() timed out after 10000msec

我想知道如果收到此错误,是否有任何方法可以调用函数。我的代码结构如下:
var Nightmare = require('nightmare');       
var nightmare = Nightmare({ show: true, waitTimeout: 10000});
nightmare.goto(my_url);
nightmare.wait(my_element);
nightmare.evaluate(function() {...});
nightmare.then(function(result) {...code that could give a promise warning...});

我可以在goto和then语句中添加catch子句(如Belfordz建议),这可以工作,但是then语句中还有其他嵌套的then语句。我更喜欢一个可以捕获任何 promise 警告或抛出的超时错误的语句。

最佳答案

该错误表示在10秒的延迟内未在当前页面上找到my_element

但是,按照您的编码方式,您正在同步调用gotowaitevaluatethen方法,而它们应由内部promise机制调用,即通过“链接”调用,否则很快就会执行:

var Nightmare = require('nightmare');       
var nightmare = Nightmare({ show: true, waitTimeout: 10000});
nightmare.goto(my_url) // <-- don't end the statement here, continue the chain:
.wait(my_element)
.evaluate(function() {...})
.then(function(result) {...});

关于javascript - 如果 Nightmare waitTimeout超出,则调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44008925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com