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()
  • 相关阅读:
    wxpython 简单例子:显示文本框的窗口显示鼠标位置
    wxpython学习:创建最小的空的wxPython程序
    wxPython学习笔记
    5G PDCCH 协议
    FPGA学习
    CCS 5.5下载地址http://www.dianyuan.com/bbs/1492792.html
    朴素贝叶斯
    决策树最后的存储 检测
    决策树 绘图
    决策树 书上的例题
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8717288.html
Copyright © 2011-2022 走看看