请注意,本文编写于 96 天前,最后修改于 95 天前,其中某些信息可能已经过时。
报错内容:Message: invalid argument: log type 'performance' not found
编译程序: Visual Studio Code 1.92.0
运行环境:Python: 3.12.4
Chrome: 127.0.6533.89(正式版本) (64 位)
selenium: 4.23.1
原代码:
capabilities = DesiredCapabilities.CHROME.copy()
capabilities['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome()
try:
driver.get(config.get("login_url"))
logs = driver.get_log('performance')
for entry in logs:
message = entry.get('message', {})
message = json.loads(message)
message = message.get('message', {})
method = message.get('method', '')
修改后代码:
#capabilities = DesiredCapabilities.CHROME.copy()
#capabilities['goog:loggingPrefs'] = {'performance': 'ALL'}
logging_prefs = {
'performance':'ALL'
}
capabilities = DesiredCapabilities.CHROME
capabilities['goog:loggingPrefs'] = logging_prefs
driver = webdriver.Chrome()
try:
driver.get(config.get("login_url"))
logs = driver.get_log('performance')
for entry in logs:
message = entry.get('message', {})
message = json.loads(message)
message = message.get('message', {})
method = message.get('method', '')
可能跟程序版本有关,能搜到的方法都尝试过但是没有成功,后来按上面代码修改后程序正常运行,分享下自己的解决方案供参考。