报错内容: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', '')

可能跟程序版本有关,能搜到的方法都尝试过但是没有成功,后来按上面代码修改后程序正常运行,分享下自己的解决方案供参考。

最后修改:2024 年 08 月 04 日
如果觉得我的文章对你有用,请随意赞赏