1

What is the correct Ruby code for configuring Selenium to access the JavaScript console (i.e., messages writing using console.log, console.error, console.info, etc.)?

I've found several articles with Java, Python, and C# code; but, I'm having trouble getting everything just right for Ruby.

Here is my best guess for Firefox:

  caps = Selenium::WebDriver::Remote::Capabilities.chrome
  caps[:loggingPref] = {:browser => :all}
  return Selenium::WebDriver.for :firefox, :desired_capabilities => caps

This code doesn't appear to affect anything (I get some logging messages, but not those generated by console.log, console.error, etc.). Therefore, I suspect I just have something spelled wrong, or a symbol where I need a string.

Chrome to provide access to console.info, console.error, and console.warn messages by default. It does not show console.log messages. I assume there is a similar technique for configuring the Chrome driver to return all messages; but, again, I can't find just the right combination of keys, values, symbols, and strings to make it work.

Zack
  • 6,232
  • 8
  • 38
  • 68
  • Here is the post discussing Python code:http://stackoverflow.com/questions/20907180/getting-console-log-output-from-chrome-with-selenium-python-api-bindings – Zack Jun 29 '15 at 16:14
  • here is the post discussing Java code: http://stackoverflow.com/questions/18261338/get-chromes-console-log/18283831#18283831 – Zack Jun 29 '15 at 16:15

1 Answers1

0

The capability is called :logging_prefs in ruby and the :browser parameter is a string value.

Here's the code (you were quite close!):

caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps[:logging_prefs] = {:browser => "ALL"}
return Selenium::WebDriver.for :firefox, :desired_capabilities => caps

Then you can get the log messages with driver.manage.logs.get(:browser)

sokkyoku
  • 2,161
  • 1
  • 20
  • 22