Created
September 30, 2025 21:10
-
-
Save cgoldberg/f8302e918d1076296f46e640c4d5aa21 to your computer and use it in GitHub Desktop.
Python/Selenium - launch Chrome and load a web page with all possible logging enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # launch Chrome and navigate to a web page with all console logging enabled | |
| # - chrome/chromedriver logs go to STDOUT | |
| # - captured driver/performance logs go to STDOUT | |
| # - selenium debug logs go to STDERR | |
| import logging | |
| import subprocess | |
| from selenium import webdriver | |
| logging.basicConfig(level=logging.DEBUG) | |
| LOG_TYPES = ("driver", "performance") | |
| service = webdriver.ChromeService(log_output=subprocess.STDOUT) | |
| options = webdriver.ChromeOptions() | |
| logging_prefs = {log_type: "ALL" for log_type in LOG_TYPES} | |
| options.set_capability("goog:loggingPrefs", logging_prefs) | |
| driver = webdriver.Chrome(options=options, service=service) | |
| driver.get("https://example.com") | |
| for log_type in LOG_TYPES: | |
| print("-" * 80) | |
| print(f"{log_type} logs:") | |
| print("-" * 20) | |
| for entry in driver.get_log(log_type): | |
| pass # print(entry) | |
| driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment