Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Chrome can't see browser logs InvalidArgumentException

I am trying to get the HTTP status code after opening a website with selenium webdriver with Python, i saw getting HTTP status code is not possible so the only way is to get the network logs and get the HTTP status code from there

so i am trying to print the logs in selenium but it is giving me a InvalidArgumentException

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'performance':'ALL' }

driver = webdriver.Chrome(desired_capabilities=d)

# load the desired webpage
driver.get('http://foo.com')

# print messages
for entry in driver.get_log('performance'):
    print(entry)

And this is the error after running

InvalidArgumentException                  Traceback (most recent call last)
<ipython-input-13-8480733201dc> in <module>
     12 
     13 # print messages
---> 14 for entry in driver.get_log('performance'):
     15     print(entry)

c:\users\slimshady\appdata\local\programs\python\python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py in get_log(self, log_type)
   1260             driver.get_log('server')
   1261         """
-> 1262         return self.execute(Command.GET_LOG, {'type': log_type})['value']

c:\users\slimshady\appdata\local\programs\python\python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

c:\users\slimshady\appdata\local\programs\python\python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

InvalidArgumentException: Message: invalid argument: log type 'performance' not found
  (Session info: chrome=75.0.3770.80)

What might i be doing wrong here ?

like image 547
Shantanu Bedajna Avatar asked Dec 02 '22 10:12

Shantanu Bedajna


1 Answers

As specified in the release notes for Chrome Driver 75, capability loggingPrefs has been renamed to goog:loggingPrefs, as required by W3C standard. Thus, the code setting the capabilities should be adjusted and there will be no necessity of falling back to non-w3c mode at least due to the log capturing reason.

d['goog:loggingPrefs'] = { 'performance':'ALL' }
like image 188
Alexey Subach Avatar answered Mar 30 '23 00:03

Alexey Subach