Getting console.log output from Firefox with Selenium Getting console.log output from Firefox with Selenium selenium selenium

Getting console.log output from Firefox with Selenium


Your code is correct when it comes to the get_log function, just add a print statement at the end like so:

from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilities# enable browser loggingd = DesiredCapabilities.FIREFOXd['loggingPrefs'] = {'browser': 'ALL'}driver = webdriver.Firefox(capabilities=d)# load some sitedriver.get('http://foo.com')# print messagesfor entry in driver.get_log('browser'):    print entryprintdriver.quit()

In fact:

print len(driver.get_log('browser'))

returns 53 in my example with this as a sample entry in the list:

{u'timestamp': 1407591650751, u'message': u"Expected ':' but found '}'.  Declaration dropped.", u'level': u'WARNING'}

Seems like a bad char problem. As for why there is no output in the /tmp/firefox_console file, I have no clue, the logger seems to throw some webdriver debug info but no console.log output.

EDIT: Apparently the above code does not return data from console.log. It's not a Selenium bug as far as I can tell but a problem with Firefox. I managed to get around it by installing the Firebug along with ConsoleExport plugin for Firebug, then point it to some logging server. See also this SO answer for details on how to enable Firebug programmatically from Selenium.

See this gist for more details: https://gist.github.com/CGenie/fc63536a8467ae6ef945


There have been changes in implementation. I was also using:

d = DesiredCapabilities.FIREFOXd['loggingPrefs'] = {'browser': 'ALL'}

but now I am using Python3.8, Selenium 3.4 and it is not working/implemented anymore.See another Stackoverflow question discussing it.

Otherwise you get the error:selenium.common.exceptions.WebDriverException: Message: loggingPrefs is not the name of a known capability or extension capability