pythonseleniumselenium-chromedriver

Read stdout and stderr logs from selenium controlled chrome browser


I made some minor modifications to the Chromium browser and built a custom version that does some logging on stderr. I would like to control this browser with Selenium (Python version) and read these stderr logs.

The following is a minimal example of what I am doing:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os.path    

options = Options()
options.binary_location = '/home/phani/chromium/src/out/Default/chrome'
options.add_argument('--user-data-dir=/tmp/')
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=options)
driver.get('http://www.facebook.com')

Can someone tell me how I can read the logs produced by the Chromium browser? For Firefox, there is an argument called "log_file" which allows us to direct output from the browser to stdout/stderr if we prefer. https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_binary.html#module-selenium.webdriver.firefox.firefox_binary

Is there something similar for Chromium?


Solution

  • Yes,

    In Chrome you can pass the logging as a parameter like this:

    driver = webdriver.Chrome(executable_path="Path\\to\\your\\chromedriver", service_args=["--verbose", "--log-path=C:\\path\\to\\log"])
    

    Where the --verbose creates verbose logging instead of just errors, and --log-path is a filepath in case you want to write out the log to file.

    The logging documentation for Chrome is HERE

    As per you comment, you can get information on headless logging HERE.