Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 251
phk Avatar asked Jul 10 '19 06:07

phk


1 Answers

You probably need to enable the debugger before the command:

driver.execute_cdp_cmd("Debugger.enable", {})
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})
like image 182
Florent B. Avatar answered Oct 13 '22 11:10

Florent B.