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

M1 Mac上Selenium启动失败,报selenium.common.exceptions.WebDriverException求助

Selenium启动失败,抛出selenium.common.exceptions.WebDriverException: Message:异常的解决方法

问题描述

Mac M1 Pro环境下,启动Selenium Chrome驱动时持续抛出空消息的WebDriverException,尝试手动指定ChromeDriver路径、使用ChromeDriver Manager均无效,关闭现有Chrome窗口也无法解决。

环境信息:

Mac M1 pro
Chrome version: 107.0.5304.87
ChromeDriver: 107.0.5304.62
selenium version: 4.5.0

尝试过的操作:

  1. 手动指定ChromeDriver路径的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service


s = Service('/Users/itsmeleah/code/itsmeleahh/Get-Taobao-Data/chromedriver')
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(service=s, options=chrome_options)

driver.get('https://www.google.com')
  1. 使用ChromeDriver Manager的代码:
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://www.google.com")

两种方式均抛出相同的空消息WebDriverException,无浏览器窗口弹出。

解决方案(针对M1 Mac架构)

  • 下载ARM64版本的ChromeDriver:M1为ARM架构,需使用对应版本的ChromeDriver,而非x86版本。重新下载与Chrome版本匹配的mac-arm64版ChromeDriver,替换现有文件或在代码中指定新路径。
  • 添加M1兼容启动参数:在ChromeOptions中加入--enable-features=VizDisplayCompositor参数,解决架构兼容的渲染问题,示例代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

chrome_options = Options()
chrome_options.add_argument("--enable-features=VizDisplayCompositor")
chrome_options.add_argument("--headless=new")  # 无头模式建议用新版参数
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

s = Service('/path/to/arm64-version/chromedriver')
driver = webdriver.Chrome(service=s, options=chrome_options)
driver.get('https://www.google.com')
  • 赋予ChromeDriver可执行权限:终端执行命令为chromedriver添加权限:
chmod +x /path/to/your/chromedriver
  • 升级Selenium版本:Selenium 4.5.0对M1架构的兼容性有限,升级到最新稳定版:
pip install --upgrade selenium
  • 验证版本严格匹配:确保ChromeDriver的版本号与Chrome浏览器完全对应,ARM版需下载对应版本包,避免跨架构版本混用。

内容的提问来源于stack exchange,提问作者Lai Leah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 09:05:22