使用selenium打开浏览器之后,有浏览器内部的提示设置默认浏览器等,怎么屏蔽或关闭这些提示

当使用Selenium打开浏览器时,可能会遇到浏览器内部的一些提示或弹窗,例如设置默认浏览器的提示。你可以通过配置选项或设置浏览器参数来屏蔽或关闭这些提示。

以下是针对不同浏览器的一些方法:

对于Chrome浏览器:

  1. 在创建ChromeDriver实例之前,设置ChromeOptions以禁用浏览器弹窗:

    python 复制代码
    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-infobars")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--disable-browser-side-navigation")
    options.add_argument("--disable-gpu")
    options.add_argument("--disable-notifications")
    options.add_argument("--disable-popup-blocking")
    options.add_argument("--disable-default-apps")
    options.add_argument("--disable-extensions")
    
    driver = webdriver.Chrome(options=options)

对于Firefox浏览器:

  1. 在创建FirefoxDriver实例之前,设置FirefoxProfile以禁用弹窗:

    python 复制代码
    from selenium import webdriver
    
    profile = webdriver.FirefoxProfile()
    profile.set_preference("dom.webnotifications.enabled", False)
    
    driver = webdriver.Firefox(firefox_profile=profile)

对于其他浏览器,你可以查阅相关文档或参考其对应的浏览器驱动程序的配置选项,以了解如何禁用或关闭特定的提示或弹窗。

请注意,不同的浏览器和浏览器版本可能具有不同的配置选项和参数。因此,建议查阅相关的浏览器驱动程序文档,了解更多关于禁用或关闭特定提示的详细信息。加粗样式

相关推荐
will_net2 小时前
web自动化(四)日期控件
selenium·自动化·drissionpage
2401_857026234 小时前
Postman中Pre-request Script的编写与应用实践
测试工具·lua·postman
Apifox.15 小时前
如何将 Apifox 的自动化测试与 Jenkins 集成?
功能测试·测试工具·ci/cd·jenkins·devops
明天吃啥。15 小时前
【软件测试】之自动化测试
selenium
大霸王龙1 天前
静态资源介绍 selenium
selenium·测试工具
Aaron_9451 天前
PyAutoGUI 使用详解
python·测试工具
猫猫爱吃小鱼粮1 天前
53、Flink 测试工具测试用户自定义函数详解
测试工具·flink
猫猫村晨总1 天前
使用Python3和Selenium打造百度图片爬虫
爬虫·python·selenium
测试萧十一郎1 天前
推荐三款常用接口测试工具!
自动化测试·软件测试·功能测试·测试工具·程序人生·职场和发展
小小测开1 天前
postman请求访问:认证失败,无法访问系统资源
测试工具·postman