You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium 4.6无法自动匹配对应版本ChromeDriver问题求助

问题:Selenium 4.6集成的Selenium Manager无法自动匹配ChromeDriver版本

环境信息

  • Selenium版本:v4.6
  • Chrome浏览器版本:115.0.5790.171

报错信息

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 101 Current browser version is 115.0.5790.171 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

爬虫代码

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import pandas as pd
import time

custom_options = webdriver.ChromeOptions()
custom_options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

service = Service()
options = Options()
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://lr.caa.cz/letecky-rejstrik?lang=en")

data = []

while True:
    try:
        print("Page source:")
        print(driver.page_source)
        print("Waiting for table rows to load...")
        rows_length = len(WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.XPATH, "//tbody/tr"))))
        print(f"Found {rows_length} rows")
        for i in range(rows_length):
            row_data = []
            print("Waiting for table data to load...")
            table_data = WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.XPATH, f"//tbody/tr[{i+1}]/td")))
            for j in table_data:
                row_data.append(j.text.strip())
            data.append(row_data)
            print(row_data)
        next_button = None
        try:
            print("Trying to find next button...")
            next_button = driver.find_element("xpath", '/html/body/app-root/div/main/div/div/app-avreg-list/nav/div/app-pagination/div/a[3]')
        except Exception as e:
            print(f"Error finding next button: {e}")
            break
        if not next_button:
            print("Next button not found")
            break
        try:
            if "disabled" in next_button.get_attribute("class"):
                print("Next button is disabled")
                break
            print("Clicking next button")
            driver.execute_script("arguments[0].click();", next_button)
            time.sleep(1)
        except Exception as e:
            print(f"Error clicking next button: {e}")
            break
    except Exception as e:
        print(f"Error: {e}")
        break

print(f"Collected {len(data)} rows of data")
df = pd.DataFrame(data)
df.to_csv("CZ register.csv", index=False)

driver.quit()

当前临时解决方法

手动指定本地ChromeDriver路径:

# path_to_chromedriver = r'C:\Chromedriver\chromedriver.exe'  
# driver = webdriver.Chrome(service=Service(path_to_chromedriver), options=custom_options)

需求

无需指定本地ChromeDriver路径,让Selenium自动静默下载匹配的驱动,避免版本不匹配报错。


解决方法

1. 清理旧版本ChromeDriver残留

  • 检查系统PATH环境变量,移除包含旧版本ChromeDriver(v101)的路径,确保Selenium不会优先调用旧驱动。
  • 删除Selenium Manager的缓存目录:Windows下路径为%USERPROFILE%\.cache\selenium,删除该目录下的chromedriver相关文件,强制重新下载匹配版本。

2. 修正代码的Options配置

代码中同时定义了custom_options和options,但初始化driver时未使用配置好的custom_options,统一配置如下:

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

service = Service()
driver = webdriver.Chrome(service=service, options=options)

3. 升级Selenium版本

Selenium 4.6的Selenium Manager对Chrome 115这类较新版本的支持存在bug,升级到4.10及以上版本可修复更多适配问题,新版本的Selenium Manager能更好地匹配高版本Chrome。

4. 查看Selenium Manager日志排查问题

设置环境变量SE_DEBUG=true,运行脚本后查看日志,确认Selenium Manager是否尝试下载驱动、是否存在下载失败或路径识别错误的情况,针对性解决。


内容的提问来源于stack exchange,提问作者Mark k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 17:33:37