Disable flash in saucelabs/selenium webdriver?

[亡魂溺海] 提交于 2019-12-23 17:17:37

问题


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.


回答1:


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())


来源:https://stackoverflow.com/questions/17113477/disable-flash-in-saucelabs-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!