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

ChromeDriver无法打开网页求助:配置文件选择窗口闪退报错

问题:Chrome启动时弹出配置选择窗口后闪退,无法打开URL

运行代码时,Chrome会弹出用户配置文件选择界面,随后窗口快速闪退,程序报错。相关代码如下:

import time
import pyautogui
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from pynput.keyboard import Key, Controller
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from seleniumbase import Driver

service = Service()
options = webdriver.ChromeOptions()
#driver = webdriver.Chrome(service=service, options=options)
driver = Driver(browser="chrome", headless=False)

url = "https://www.google.de/"
driver.get(url)

弹出窗口为Chrome的用户配置文件选择界面,显示多个用户配置选项,要求选择要使用的配置文件。


解决方法

  • 指定固定用户配置文件启动
    找到Chrome的用户配置文件路径(Windows默认路径:C:\Users\<你的用户名>\AppData\Local\Google\Chrome\User Data;macOS:~/Library/Application Support/Google/Chrome;Linux:~/.config/google-chrome),然后在配置中添加参数:
options.add_argument(r"--user-data-dir=C:\Users\<你的用户名>\AppData\Local\Google\Chrome\User Data")
options.add_argument(r"--profile-directory=Default")  # 替换为你要使用的配置文件夹名,比如"Profile 1"
# 若使用SeleniumBase Driver,传入options
driver = Driver(browser="chrome", headless=False, options=options)
  • 跳过配置文件选择,使用临时配置
    添加参数让Chrome直接跳过配置选择流程:
options.add_argument("--disable-user-profile-detection")
options.add_argument("--no-default-browser-check")
options.add_argument("--start-maximized")
  • 确保版本兼容
    Chrome浏览器、ChromeDriver、Selenium及SeleniumBase版本必须匹配:

    • 用webdriver-manager自动匹配驱动(原生Selenium方式):
      service = Service(ChromeDriverManager().install())
      driver = webdriver.Chrome(service=service, options=options)
      
    • 更新SeleniumBase:pip install --upgrade seleniumbase
  • 避免库冲突
    代码同时导入了原生Selenium驱动和SeleniumBase Driver,可能引发冲突,建议只保留一种驱动初始化方式,不要混合使用。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 10:02:01