使用Selenium在Chrome中打破异常 [英] Break on exception in Chrome using Selenium

查看:70
本文介绍了使用Selenium在Chrome中打破异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了调查一些硒测试失败,我想自动启用

In order to investigate some Selenium test failures I would like to automatically enable the pause on exception feature in the Chrome Devtools when running the tests.

-auto-open-devtools-for-tabs 命令行选项,用于自动打开我已经在使用的DevTools窗格,但是显然没有用于自动暂停的CLI选项/参数我正在寻找的功能.

There is the --auto-open-devtools-for-tabs command line option for automatically opening the DevTools pane which I am already using but apparently there is no CLI option/parameter for the autopause feature I am looking for.

我遇到的是 Debugger.setPauseOnExceptions Chrome Devtools协议命令,我尝试使用

What I came across though is the Debugger.setPauseOnExceptions Chrome Devtools Protocol command which I tried activating using execute_cdp_cmd(I am using Selenium for Python):

driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})

不幸的是,即使打开了选项卡(包括DevTools窗格),我也得到了

Unfortunately, even when the tab is open (including the DevTools pane) I am getting

unhandled inspector error: {"code":-32000,"message":"Debugger agent is not enabled"}

我在做什么错或者还有其他可以使用的方式(最好是可靠且可移植的方式,请不要使用任何宏东西)?

推荐答案

您可能需要在以下命令之前启用调试器:

You probably need to enable the debugger before the command:

driver.execute_cdp_cmd("Debugger.enable", {})
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})

这篇关于使用Selenium在Chrome中打破异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆