使用Selenium在Chrome中打破异常 [英] Break on exception in Chrome using Selenium
问题描述
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屋!