在saucelabs / selenium webdriver中禁用闪存? [英] Disable flash in saucelabs/selenium webdriver?

查看:209
本文介绍了在saucelabs / selenium webdriver中禁用闪存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用saucelabs来自动执行几个网站的屏幕截图,以确保更改后的代码不会中断任何事情。我正在使用python的webdriver编程,需要禁用Chrome,Firefox和IE浏览器的Flash。我试图在网上找到答案,但没有一个似乎是禁用闪光灯,只与闪光对象交互。

解决方案

下面的代码将适用于Chrome,它禁用闪光灯,并将默认的下载目录设置到一个不同的文件夹。

  from selenium .webdriver.chrome.options import选项
def _disable_flash_caps(self):
chromeOptions = Options()
#prefs = {download.default_directory:C:\\temp ,profile.managed_default_content_settings.plugins:2}
prefs = {download.default_directory:C:\\temp,plugins.plugins_disabled:[Adobe Flash Player]}
chromeOptions.add_experimental_option(prefs,prefs)
return chromeOptions.to_capabilities()

调用它:

 如果'browserName'在cap和cap ['browserName'] =='chrome':
webdriver.Remote._ _init __(self,sel_url,self._disable_flash_caps())


I am trying to use saucelabs to automate taking screenshots of several sites to make sure that changing code doesn't break things. I'm programming using webdriver for python and need to disable flash on chrome, firefox and IE. I've tried to find the answers online but none of them seem to be for disabling flash, only interacting with flash objects.

解决方案

The below code will work for chrome, it disables the flash and sets the default download directory to a different folder.

from selenium.webdriver.chrome.options import Options   
def _disable_flash_caps(self):
      chromeOptions = Options()
      # prefs = {"download.default_directory" : "C:\\temp", "profile.managed_default_content_settings.plugins": 2}
      prefs = {"download.default_directory" : "C:\\temp", "plugins.plugins_disabled": ["Adobe Flash Player"] }
      chromeOptions.add_experimental_option("prefs",prefs)
      return chromeOptions.to_capabilities()

call it with:

if 'browserName' in cap and cap['browserName'] == 'chrome':
   webdriver.Remote.__init__(self, sel_url, self._disable_flash_caps())

这篇关于在saucelabs / selenium webdriver中禁用闪存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆