How to enable Chromedriver logging

When using Chrome for Selenium tests, the chromedriver binary will be used to control Chrome. To debug problems that stem from Selenium's Chrome and/or Chromedriver, you might want to enable logging for the chromedriver itself. Here is how.

Option 1: Use Selenium::WebDriver::Service

In your test setup, you may already have something like, browser: :chrome, options: ...), especially when passing options like device emulation.

Similar to options, simply add an extra key service and pass an instance of Selenium::WebDriver::Service like so:

service = { verbose: true, log_path: '/tmp/chromedriver.log' }), browser: :chrome, options: ..., service: service)

Note that version 3.x also supports passing the service arguments as driver_opts directly. However, this is deprecated and will be removed in version 4 of selenium-webdriver.

Option 2: Connect tests to a manually started chromedriver

If the above approach no longer works, or if you want to go bare metal, you can also start chromedriver yourself in a terminal on a custom port:

chromedriver --port=12345 --verbose --log-path=/tmp/chromedriver.log

Then configure Selenium to connect to that port. Like in option 1, you need to pass an extra key when creating your driver instance., browser: :chrome, options: ..., url: 'http://localhost:12345')

Note that you may omit the --log-path option to make chromedriver print to your terminal.

Arne Hartherz about 3 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more