About Reading console.log() Output via Selenium
Selenium is able to read the console.log() output from Chrome browser. Here's how:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
driver_path = settings.BASE_DIR / "drivers" / "chromedriver"
chrome_options = Options()
chrome_options.set_capability(
"goog:loggingPrefs",
{"browser": "ALL", "driver": "ALL", "performance": "ALL"},
)
browser = webdriver.Chrome(
service=ChromeService(executable_path=driver_path),
options=chrome_options,
)
# ... browse the website here ...
logs = self.browser.get_log("browser")
for log in logs:
if log["level"] == "INFO":
print(log["message"])
Besides the message itself, the message entry will contain some meta information that can be stripped out with your custom regular expression.
Also by me
Django Messaging app
For Django-based social platforms.
Django App for You
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You