为了调查一些 Selenium 测试失败,我想自动启用 pause on exception feature in the Chrome Devtools在运行测试时。
--auto-open-devtools-for-tabs
命令行选项可自动打开我已经在使用的 DevTools Pane ,但显然没有用于自动暂停的 CLI 选项/参数我正在寻找的功能。
虽然我遇到的是 Debugger.setPauseOnExceptions
Chrome Devtools Protocol command我尝试使用 execute_cdp_cmd
激活它(我正在为 Python 使用 Selenium):
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})
不幸的是,即使选项卡处于打开状态(包括 DevTools Pane ),我也会收到
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"})
关于python - 使用 Selenium 在 Chrome 中中断异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56964779/