Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (29.3k points)

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?

closed

2 Answers

+4 votes
by (50.2k points)
selected by
 
Best answer

Use this below code that will resolve this issue

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)

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

d['goog:loggingPrefs'] = { 'browser':'ALL' }

If you wish to Learn Selenium visit this Selenium Certification by Intellipaat.

If you wish to learn more about Python, visit the Python tutorial and Python course by Intellipaat.

Getting console.log output from Chrome with Selenium Python API bindings
Intellipaat-community
by (19.7k points)
Exploring how to do this with chrome_options after trying this out and getting:


/usr/lib/python2.6/site-packages/selenium/webdriver/chrome/webdriver.py:54: DeprecationWarning: Desired Capabilities has been deprecated, please user chrome_options. warnings.warn("Desired Capabilities has been deprecated, please user chrome_options.", DeprecationWarning)
by (33.1k points)
This answer solved my problem.
Thanks!
by (44.4k points)
I had this issue with selenium 2.33.0, after upgrading it to 2.45.0 fixed it.
by (47.2k points)
Entries whose source field equals 'console-api' correspond to console messages, and the message itself is stored in the message field.
by (19.9k points)
This worked for me. Thanks.
by (41.4k points)
Thanks a lot for you answer.It worked
+1 vote
by (107k points)

To complete the answer: starting from chromedriver 75.0.3770.8, you have to use goog:loggingPrefs instead of loggingPrefs.

See Chromedriver changelog: http://chromedriver.chromium.org/downloads or this bug: https://bugs.chromium.org/p/chromedriver/issues/detail?id=2976

Getting console.log output from Chrome with Selenium Python API bindings
Intellipaat-community
by (29.5k points)
Thanks for adding the comment made me understand the answer !
by (32.1k points)
Upgrading the software helped me.
Try doing that as well if this doesn't work.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...