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

Python中禁用Selenium Edge WebDriver弹窗通知及隐私模式失效问题

禁用Edge WebDriver各类通知弹窗的解决方案

要彻底关闭Edge WebDriver启动时的Personalized_Setting、Profile_Setting、Cookies弹窗,同时确保隐私模式生效,可通过配置EdgeOptions的多个参数实现,以下是具体实现步骤:

核心配置方向

  • 启用正确的隐私模式
  • 禁用浏览器通知权限
  • 跳过首次运行的配置引导
  • 关闭个性化推荐模块
  • 自动处理Cookie授权

完整代码示例

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

edge_options = Options()

# 启用Edge隐私模式
edge_options.add_argument("--inprivate")

# 全局禁用通知请求弹窗
edge_options.add_argument("--disable-notifications")

# 跳过首次启动的配置文件设置与默认浏览器检查
edge_options.add_argument("--no-first-run")
edge_options.add_argument("--no-default-browser-check")

# 关闭个性化设置相关功能模块
edge_options.add_argument("--disable-features=PersonalizationSettings")

# 自动允许所有Cookie,跳过授权弹窗
edge_options.add_experimental_option("prefs", {
    "profile.default_content_setting_values.cookies": 1,
    "profile.cookie_controls_mode": 0  # 0=允许所有Cookie,1=阻止第三方,2=阻止所有
})

# 初始化WebDriver
driver = webdriver.Edge(options=edge_options)
driver.get("你的目标网址")

参数说明

  • --inprivate:Edge官方标准的隐私模式启动参数,替代无效的ms:inPrivate写法
  • --disable-notifications:直接阻止浏览器向系统请求通知权限的弹窗
  • --no-first-run&--no-default-browser-check:跳过首次启动时的配置文件引导和默认浏览器提示
  • --disable-features=PersonalizationSettings:关闭个性化推荐相关的功能模块,从根源屏蔽对应弹窗
  • Cookie偏好配置:通过修改浏览器预设,自动同意所有Cookie授权,无需手动交互

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 12:12:08