0

I have a problem, I need create a log from my test (Selenium, python). I know how to write all logs,

That is too much. I would like only logs with errors. In addition, I noticed that I do not have a "POST" log in. How to correct the code?

  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities        
        caps = DesiredCapabilities.CHROME
        caps['loggingPrefs'] = {'performance': 'ALL'}
        self.driver = webdriver.Chrome(desired_capabilities=caps)
        self.driver.get('http://site/login')
        for entry in self.driver.get_log('performance'):
            print(entry['message'])

thank you

Tom Tom
  • 23
  • 2
  • 10

2 Answers2

1

You need to set the log level:

EDIT:

Just change this line: caps['loggingPrefs'] = {'performance': 'ALL'}

To:

caps['loggingPrefs'] = {'performance': 'WARNING'}

If you are using local log you can try setting the level with options:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('log-level=1')
driver = webdriver.Chrome(r'C:\path\to\chromedriver', chrome_options=options)

This is the levels:

  • INFO = 0,
  • WARNING = 1,
  • LOG_ERROR = 2,
  • LOG_FATAL = 3.

The default is 0

Hope this helps you!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • @TomTom see edit... just add the `options` to the driver – Moshe Slavin Jan 28 '19 at 11:51
  • Yes, I make how you write, but I have yet all network from selenium.webdriver.common.desired_capabilities import DesiredCapabilities caps = DesiredCapabilities.CHROME caps['loggingPrefs'] = {'performance': 'warning'} self.driver = webdriver.Chrome(desired_capabilities=caps) self.driver.get('http://10.0.0.3:8541/login') for entry in self.driver.get_log('performance'): print(entry['message']) – Tom Tom Jan 28 '19 at 12:13
  • I know a problem is with: for entry in self.driver.get_log('performance'): print(entry['message']) – Tom Tom Jan 28 '19 at 12:15
  • I should change performance to performance WARNING, but I dont know how – Tom Tom Jan 28 '19 at 12:16
1

See the updated answer at https://stackoverflow.com/a/20910684/10525667.

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

d['goog:loggingPrefs'] = { 'browser':'ALL' }
Peter
  • 202
  • 2
  • 5
  • Strangest thing.. I have been using `loggingPrefs` without issue until now. This was using the latest drivers too. I can't explain why it worked without `goog:` for the past couple years. – Marcel Wilson Jul 12 '23 at 15:06