zoukankan      html  css  js  c++  java
  • webdriver高级应用- 禁止Chrome浏览器的PDF和Flash插件

    #encoding=utf-8
    from selenium import webdriver
    # 导入Options类
    from selenium.webdriver.chrome.options import Options
    import unittest, time
    
    class TestDemo(unittest.TestCase):
    
        def setUp(self):
            # 创建Chrome浏览器的一个Options实例对象
            chrome_options = Options()
            # 设置Chrome浏览器禁用PDF和Flash插件,把图片也关掉了。
            profile = {"plugins.plugins_disabled": ['Chrome PDF Viewer'],
                       "plugins.plugins_disabled": ['Adobe Flash Player'],
                       "profile.managed_default_content_settings.images":2}
    
    
            chrome_options.add_experimental_option("prefs", profile)
            prefs = {"profile.managed_default_content_settings.images":2}
            chrome_options.add_experimental_option("prefs", profile)
            # 向Options实例中添加禁用扩展插件的设置参数项
            chrome_options.add_argument("--disable-extensions")
            # 添加屏蔽--ignore-certificate-errors提示信息的设置参数项
            chrome_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
            # 添加浏览器最大化的设置参数项,启动同时最大化窗口
            chrome_options.add_argument('--start-maximized')
            # 启动带有自定义设置的Chrome浏览器
            self.driver = webdriver.Chrome(executable_path="e:\chromedriver", chrome_options=chrome_options)
    
        def test_forbidPdfFlashChrome(self):
            # 访问爱奇艺首页
            self.driver.get("http://www.iqiyi.com")
            # 等待50秒,期间可以看到页面由于禁用了Flash插件,
            # 导致需要Flash支持的内容无法正常展示
            time.sleep(10)
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    设计模式一 Simple Factory, Factory Method, Abstract Factory以及Builder模式简述
    SQL Server中对XML操作
    开发常用小工具介绍
    强制休息程序 EyeGuardian 眼睛守护者 Beta测试版
    定时计划任务方案比较以及通过脚本创建计划任务(SchTasks命令)
    在Myeclipse中配置Maven
    Jena的环境配置
    0x01_go代码简单示例
    0x00_go语言安装
    信息收集工具
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8717288.html
Copyright © 2011-2022 走看看