To investigate Selenium test failures due to Javascript errors (in Google Chrome) I am running the tests locally (non-headless-ly) with the --auto-open-devtools-for-tabs
command line option for Chrome in combination with the Debugger.setPauseOnExceptions
Chrome Devtools Protocol command (see also Break on exception in Chrome using Selenium).
Apparently this does not work (any more), a small test case in Selenium for Python:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
options = webdriver.chrome.options.Options()
options.add_argument('--auto-open-devtools-for-tabs')
driver = webdriver.Chrome(
options=options,
service_args=["--verbose", "--log-path=chromedriver.log"]
)
wait = WebDriverWait(driver, 5)
page = """
<html>
<head><title>Test</title></head>
<body>
<script>
function errorTest() {
setTimeout(() => alert('It should pause before me!'), 1000)
throw new Error('Foobar')
}
</script>
<button id="btn" onclick="errorTest()">Click me</button>
</body>
</html>
"""
driver.get("data:text/html;charset=utf-8," + page)
wait.until(
EC.title_contains("Test"),
"Page did not load"
)
driver.execute_cdp_cmd("Debugger.enable", {})
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})
driver.find_element_by_id("btn").click()
According to chromedriver.log
the CDP commands seem to be accepted properly. Is there something I missed?
Current (stable) Selenium client (3.141.0) on Python 3.8 and current Google Chrome (83).