Selenium Chrome не видит журналы браузера InvalidArgumentException - PullRequest
0 голосов
/ 08 июня 2019

Я пытаюсь получить код состояния HTTP после открытия веб-сайта с помощью селенового веб-драйвера на Python, я увидел, что получить код статуса HTTP невозможно, поэтому единственный способ - это получить сеть регистрирует и получает оттуда код состояния HTTP

, поэтому я пытаюсь распечатать журналы в селене, но это дает мне 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)

И это ошибка после запуска

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)

Что я могу здесь делать не так?

Ответы [ 2 ]

3 голосов
/ 10 июня 2019

Как указано в примечаниях к выпуску для Chrome Driver 75, возможность loggingPrefs была переименована в goog:loggingPrefs, как того требует стандарт W3C.Таким образом, код, устанавливающий возможности, должен быть скорректирован, и не будет необходимости возвращаться в режим, отличный от w3c, по крайней мере, по причине захвата журнала.

d['goog:loggingPrefs'] = { 'performance':'ALL' }
1 голос
/ 09 июня 2019

У той же проблемы с chrome 75 и его chromedriver установка 'w3c' в False решила проблему:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options

d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'performance':'ALL' }

chrome_options = Options()
chrome_options.add_experimental_option('w3c', False)

driver = webdriver.Chrome(desired_capabilities=d, options=chrome_options)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...