Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting console.log output from Chrome with Selenium Python API bindings

I'm using Selenium to run tests in Chrome via the Python API bindings, and I'm having trouble figuring out how to configure Chrome to make the console.log output from the loaded test available. I see that there are get_log() and log_types() methods on the WebDriver object, and I've seen Get chrome's console log which shows how to do things in Java. But I don't see an equivalent of Java's LoggingPreferences type in the Python API. Is there some way to accomplish what I need?

like image 862
msridhar Avatar asked Jan 03 '14 15:01

msridhar


People also ask

How do I export my chrome console log?

Chrome console log Select the 'Console'' tab and make sure the option 'Preserve log' is checked. Reproduce the issue. You'll see data being collected in the console window. Right click on any log statement in the console window, and click Save As… to save the log file to your computer.


1 Answers

Ok, finally figured it out:

from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities  # enable browser logging d = DesiredCapabilities.CHROME d['loggingPrefs'] = { 'browser':'ALL' } driver = webdriver.Chrome(desired_capabilities=d)  # load the desired webpage driver.get('http://foo.com')  # print messages for entry in driver.get_log('browser'):     print(entry) 

Entries whose source field equals 'console-api' correspond to console messages, and the message itself is stored in the message field.

Starting from chromedriver, 75.0.3770.8, you have to use goog:loggingPrefs instead of loggingPrefs:

d['goog:loggingPrefs'] = { 'browser':'ALL' } 
like image 62
msridhar Avatar answered Oct 26 '22 20:10

msridhar