6

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?

cheparsky
  • 514
  • 6
  • 20
phk
  • 2,002
  • 1
  • 29
  • 54

1 Answers1

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"})
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Apparently it works but only after I have navigated to a page but because of this it does not work for script which are executed right after page init (`drive.get()` is async). Also it is not visible in the DevTools that it has been activated. – phk Jul 15 '19 at 09:00