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

Python Selenium自动化报错Cloud management controller初始化终止的解决方法

解决Selenium初始化Edge/Chrome浏览器窗口秒关问题

你遇到的窗口秒关问题,核心原因是Selenium 4.x版本默认会在脚本执行完毕后自动销毁driver实例,导致浏览器关闭。你看到的那两条ERROR日志是浏览器内部的非关键性警告,和窗口关闭无关。

以下是具体解决方法:

方法1:让脚本保持运行状态

在初始化浏览器后添加阻塞代码,阻止脚本结束,从而让浏览器窗口保持打开:

from selenium import webdriver

browser = webdriver.Edge()
input("按下回车键关闭浏览器...")  # 脚本会在此等待输入,浏览器持续打开

或者使用定时阻塞(需导入time模块):

from selenium import webdriver
import time

browser = webdriver.Edge()
time.sleep(30)  # 浏览器保持打开30秒,超时后自动关闭

方法2:配置浏览器选项强制保留窗口

通过EdgeOptions(Chrome对应ChromeOptions)添加detach参数,让浏览器在脚本结束后继续运行:

from selenium import webdriver
from selenium.webdriver.edge.options import Options

edge_options = Options()
edge_options.add_experimental_option("detach", True)

browser = webdriver.Edge(options=edge_options)

如果是Chrome浏览器,对应代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

browser = webdriver.Chrome(options=chrome_options)

额外环境验证(可选)

  • 确认浏览器与对应WebDriver版本完全一致(你当前的114.0.1823.67版本匹配,无需操作)
  • Selenium 4.6+版本已支持自动管理WebDriver,无需手动指定驱动路径;若版本较低,需确保驱动文件路径正确,可通过executable_path参数指定,例如:webdriver.Edge(executable_path="msedgedriver.exe")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 02:17:16