Chrome127适配Chromedriver失败,Selenium报错及PATH配置问题求助
ChromeDriver与Selenium启动报错解决方案
问题核心
Chrome版本127.0.6533.89,已下载对应127.0.6533.88版本的chromedriver并加入系统PATH,但运行Python代码时仍触发以下异常:
- Selenium Manager反复尝试旧版本chromedriver(126至122),无法识别已下载的127版本
- 提示
'chromedriver.exe' executable needs to be in PATH
报错信息
Traceback (most recent call last): File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start path = SeleniumManager().driver_location(browser) File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 74, in driver_location result = self.run((binary, flag, browser)) File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 93, in run raise SeleniumManagerException(f"Selenium manager failed for: {command}.\n{stdout}{stderr}") selenium.common.exceptions.SeleniumManagerException: Message: Selenium manager failed for: C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome. WARN Error getting version of chromedriver 127. Retrying with chromedriver 126 (attempt 1/5) WARN Error getting version of chromedriver 126. Retrying with chromedriver 125 (attempt 2/5) WARN Error getting version of chromedriver 125. Retrying with chromedriver 124 (attempt 3/5) WARN Error getting version of chromedriver 124. Retrying with chromedriver 123 (attempt 4/5) WARN Error getting version of chromedriver 123. Retrying with chromedriver 122 (attempt 5/5) ERROR The chromedriver version cannot be discovered During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\Users\Kovy\Desktop\Programs\teumim.py", line 62, in <module> first_name, last_name = get_webpage() File "c:\Users\Kovy\Desktop\Programs\teumim.py", line 19, in get_webpage driver = webdriver.Chrome(service=service, options=chrome_options) File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 80, in __init__ super().__init__( File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 101, in __init__ self.service.start() File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start raise err File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start self._start_process(self.path) File "C:\Users\Kovy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 209, in _start_process raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
解决方案
1. 禁用Selenium Manager自动驱动查找
Selenium 4.x默认启用Selenium Manager自动管理驱动,可能会忽略手动指定的路径。在ChromeOptions中添加参数禁用该功能:
chrome_options.add_argument("--disable-selenium-manager")
修改后的get_webpage函数片段:
def get_webpage(): chrome_options = Options() chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument('--disable-dev-shm-usage') # 禁用Selenium Manager,强制使用手动指定的驱动 chrome_options.add_argument("--disable-selenium-manager") chromedriver_path = 'C:/Users/Kovy/Download/chromedriver-win64/chromedriver-win64/chromedriver.exe' service = Service(executable_path=chromedriver_path) driver = webdriver.Chrome(service=service, options=chrome_options) # 后续代码保持不变
2. 验证chromedriver路径正确性
- 检查路径是否存在拼写错误(例如
Download是否应为Downloads) - 建议将chromedriver.exe移动到更简洁的路径(如
C:/chromedriver.exe),避免嵌套过深导致识别问题
3. 确认PATH配置生效
- 重启Python IDE或终端,确保PATH修改生效
- 在命令行执行
chromedriver --version,若返回版本信息则PATH配置正确;若报错,重新检查添加的目录是否正确
4. 验证驱动版本兼容性
Chrome 127.0.6533.89与chromedriver 127.0.6533.88通常兼容,若仍有问题:
- 重新下载chromedriver,确保文件未损坏
- 若有条件,下载与Chrome完全一致版本号的chromedriver
内容的提问来源于stack exchange,提问作者Kovy Jacob
相关产品推荐
相关产品推荐

