Capture browser console logs with capybara

Viewed 11004

I need to capture the console logs (category: info) of a browser using Ruby & Capybara. Until now I have tried using driver.manage.logs.get(:browser) or (:client) but, using this, the result is not what I want. It gives out the interaction results between selenium and browser where I can see my javascript statements sent for execution, but the resulting output fails to get captured.

3 Answers

Thomas Walpole answer is correct but it seems that nowadays if you are using chrome as your driver you should use

Selenium::WebDriver::Remote::Capabilities.chrome( "goog:loggingPrefs": { browser: 'ALL' } )

Notice goog:loggingPrefs instead of loggingPrefs only with this solution i was able to get console.log printed in the log.

Took me a while and got it from here https://intellipaat.com/community/5478/getting-console-log-output-from-chrome-with-selenium-python-api-bindings after several frustrating attempts.

Related