【问题标题】:Break on exception in Chrome using Selenium使用 Selenium 在 Chrome 中打破异常
【发布时间】:2019-11-19 17:33:01
【问题描述】:

为了调查某些 Selenium 测试失败,我想在运行测试时自动启用 pause on exception feature in the Chrome Devtools

--auto-open-devtools-for-tabs 命令行选项用于自动打开我已经在使用的 DevTools 窗格,但显然我正在寻找的自动暂停功能没有 CLI 选项/参数。

我遇到的是 Debugger.setPauseOnExceptions Chrome Devtools Protocol command,我尝试使用 execute_cdp_cmd 激活它(我正在使用 Selenium for Python):

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

不幸的是,即使选项卡处于打开状态(包括 DevTools 窗格),我也得到了

unhandled inspector error: {"code":-32000,"message":"Debugger agent is not enabled"}

我做错了什么还是有其他方法(最好是可靠且可移植的方法,请不要使用宏)?

【问题讨论】:

    标签: python selenium selenium-webdriver selenium-chromedriver google-chrome-devtools


    【解决方案1】:

    您可能需要在命令之前启用调试器:

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

    【讨论】:

    • 显然它有效,但只有在我导航到一个页面之后,但因此它不适用于在页面初始化后立即执行的脚本(drive.get() 是异步的)。在 DevTools 中也看不到它已被激活。
    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 2013-03-27
    • 2021-01-04
    相关资源
    最近更新 更多