gpt4 book ai didi

javascript - 如何在 CasperJS onWaitTimeout 事件处理程序中回显缺少的选择器?

转载 作者:行者123 更新时间:2023-11-30 12:21:20 24 4
gpt4 key购买 nike

我的脚本中有很多 casper.waitForSelector 部分。无论如何,我想知道它何时超时。因此我补充说:

casper.options.onWaitTimeout = function() {
//how to echo Selector which timed out here
};

此外,我想回显超时的选择器。

最佳答案

onWaitTimeout的签名是:

onWaitTimeout(Integer timeout, Object details)

遗憾的是没有正确记录。传递给函数的 details 对象包含一个表示选择器的 selector 属性。如果它是一个 XPath 选择器,那么您将需要获取它的 path 属性。

casper.options.onWaitTimeout = function(timeout, details) {
var selector = details.selector.type === 'xpath' ?
details.selector.path : details.selector;
this.echo("Wait timed out after " + timeout + " msec with selector: " + selector);
};

请注意,此函数将捕捉所有等待超时,如果您愿意,您将不得不自己退出脚本。

查看源代码总是一个好主意:1 & 2 .

关于javascript - 如何在 CasperJS onWaitTimeout 事件处理程序中回显缺少的选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30954811/

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