简体   繁体   中英

Selenium 4 Network Logging Python?

Between all versions out I seem to not understand something. I'm running selenium version 4.0.0

I have tried to run:

options.set_capability("goog:loggingPrefs", {'performance': 'ALL'})

with the following result:

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

My objective: Log the sent requests and it's responses in PYTHON for selenium i have only found JAVA examples, please help

Please have a look at: https://chromedriver.chromium.org/capabilities

I use (options omitted):

d = {}
d['goog:perfLoggingPrefs'] = {'enableNetwork': True}
driver = webdriver.Chrome(options=options, desired_capabilities=d)

(but in chromium/chrome canary I think this is on per default, because it works even with desired_capabilities=None)

It returns a list of dicts which you can sort on 'source'=='network' :

chromelog = driver.get_log('browser')
time.sleep(2) # must sleep to get activity
print([l for l in chromelog if l['source']=='network'])

Giving:

[{'level': 'SEVERE', 'message': 'https://XXXXXXXXXXXXXXX/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)', 'source': 'network', 'timestamp': 1663936185792}]

using selenium==4.4.3 and chromium==107.0.5283.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM