为了调查一些Selenium测试失败,我想在运行测试时自动启用Chrome Devtools中的异常暂停功能。
有一个--auto-open-devtools-for-tabs
命令行选项,用于自动打开我已经使用的 DevTools 窗格,但显然我没有我正在寻找的自动暂停功能的 CLI 选项/参数。
我遇到的是我尝试使用execute_cdp_cmd
激活的Debugger.setPauseOnExceptions
Chrome Devtools协议命令(我正在使用Selenium for Python(:
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})
不幸的是,即使选项卡打开(包括"开发人员工具"窗格(,我也得到了
unhandled inspector error: {"code":-32000,"message":"Debugger agent is not enabled"}
我做错了什么,或者是否有其他方法(最好是可靠且便携的方式,请不要使用宏内容(?
您可能需要在命令之前启用调试器:
driver.execute_cdp_cmd("Debugger.enable", {})
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})