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

如何关闭Microsoft Edge下载弹窗与通知?Selenium自动化求助

解决Selenium Edge自动化弹出额外窗口的问题

针对你遇到的自动化模式下弹出额外窗口导致window_handles异常的问题,除无头模式外,可通过以下几种方式阻止这类窗口显示:

1. 添加启动参数禁用首次运行与默认应用提示

直接通过启动参数阻止Edge加载欢迎页、首次运行引导类窗口:

self.edge_options.add_argument("--no-first-run")
self.edge_options.add_argument("--disable-default-apps")

2. 完善偏好设置,禁用账户与通知类弹窗

在你的prefs配置中补充以下项,关闭账户登录提示、密码管理器及通知请求:

self.prefs = {
    'download.default_directory': str(self.temp_path),
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "credentials_enable_service": False,  # 禁用凭证服务
    "profile.password_manager_enabled": False,  # 关闭密码管理器
    "profile.signin.state": "off",  # 禁用账户登录提示
    "profile.default_content_setting_values.notifications": 2  # 完全禁止通知请求
}

3. 补充更多弹窗拦截参数

添加额外的启动参数,拦截各类信息栏、弹窗:

self.edge_options.add_argument("--disable-popup-blocking")
self.edge_options.add_argument("--disable-infobars")
self.edge_options.add_argument("--disable-features=ChromeWhatsNewUI,PasswordManager")

4. 使用自定义用户配置文件(终极方案)

如果上述参数仍无效,可手动打开Edge,配置好所有弹窗、登录提示为关闭状态,然后在自动化时加载这个配置文件:

# 替换为你自己的Edge用户配置文件路径
self.edge_options.add_argument(r"--user-data-dir=C:\Users\你的用户名\AppData\Local\Microsoft\Edge\User Data\Profile 1")

修改后的完整配置示例

self.edge_options = webdriver.EdgeOptions()
self.prefs = {
    'download.default_directory': str(self.temp_path),
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "credentials_enable_service": False,
    "profile.password_manager_enabled": False,
    "profile.signin.state": "off",
    "profile.default_content_setting_values.notifications": 2
}
self.edge_options.add_experimental_option('prefs', self.prefs)
self.edge_options.add_argument("--disable-notifications")
self.edge_options.add_argument("--no-download-notification")
self.edge_options.add_argument("--no-first-run")
self.edge_options.add_argument("--disable-default-apps")
self.edge_options.add_argument("--disable-popup-blocking")
self.edge_options.add_argument("--disable-infobars")
self.edge_options.add_argument("--disable-features=ChromeWhatsNewUI,PasswordManager")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 05:17:13