捕获并处理CasperError

编程入门 行业动态 更新时间:2024-10-25 00:33:52
本文介绍了捕获并处理CasperError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用CasperJS如何捕获和处理CasperError?

Using CasperJS how do I catch and handle CasperError?

默认值似乎是继续执行程序(除了传播错误外,什么也不做)。

The default appears to continue execution of the program (which does nothing but propagates the error).

这些错误已记录到控制台/ stdout,但我似乎看不到(从文档中)捕获和处理这些错误的方法。

These errors are logged to the console/stdout but I don't seem to see a way (from the docs) to catch and handle these errors.

示例:

this.fillSelectors(selector, data);

可能会产生:

CasperError:填写表单时遇到错误:未找到表单

CasperError: Errors encountered while filling form: form not found

我知道我可以检查以确保在调用之前所有内容都存在,但是有没有办法追捕事实呢? (这也适用于许多其他操作,例如 casper.click )

I know I can check to make sure everything exists before calling, but is there a way to catch after the fact? (this applies to many other operations like casper.click as well)

推荐答案

我目前使用的是这样的东西:

I use something currently like this:

casper.on('error', function(msg,backtrace) { this.capture('./out/error.png'); throw new ErrorFunc("fatal","error","filename",backtrace,msg); });

然后我有一个自定义函数 ErrorFunc 处理所有警告或致命错误的数组。

and then I have a custom function ErrorFunc to process array of any warnings or a fatal error.

如果单击失败,则应抛出 casper.on('error') 。因此,您可以在其中放置自定义代码,以了解如何处理错误。

If you have an unsuccessful click it should throw the casper.on('error'). So you can put custom code there for how you would like to handle the error.

这里是有关Casper事件的文档。

更多推荐

捕获并处理CasperError

本文发布于:2023-11-30 05:25:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CasperError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!