Break on exception in Chrome using Selenium

六眼飞鱼酱① 提交于 2021-02-07 13:34:20

问题


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.

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.

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"})

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"}

What am I doing wrong or is there some other way (preferably a reliable and portable way, please no macro stuff) I could use?


回答1:


You probably need to enable the debugger before the command:

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


来源:https://stackoverflow.com/questions/56964779/break-on-exception-in-chrome-using-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!