【问题标题】:Disable flash in saucelabs/selenium webdriver?在 saucelabs/selenium webdriver 中禁用闪存?
【发布时间】:2013-06-11 09:32:21
【问题描述】:

我正在尝试使用 saucelabs 自动截取多个网站的屏幕截图,以确保更改代码不会破坏事情。我正在使用 python 的 webdriver 进行编程,需要在 chrome、firefox 和 IE 上禁用 flash。我试图在网上找到答案,但似乎都不是为了禁用 flash,只与 flash 对象交互。

【问题讨论】:

  • 你能分享一下你的尝试吗?
  • 就是这样,我不知道在哪里尝试。 Selenium 允许您加载自定义的 firefox 配置文件,但 saucelabs 没有那么好。这也只适用于火狐。这与其说是一个调试问题,不如说是一个“以前有人真的这样做过吗?”
  • @user2486903,我之前没有尝试过,但您可以尝试的一件事是传递禁用 Flash 捆绑版本的参数:peter.sh/experiments/chromium-command-line-switches/…
  • 根据Sauce Labs docs on custom profiles(向下滚动到“自定义 Firefox 配置文件”),这是内置在 WebDriver 的 FirefoxProfile 类中的:code.google.com/p/selenium/wiki/FirefoxDriver。对于 Chrome,请按照先前评论者的建议查看设置命令行参数。

标签: flash selenium python-2.7 selenium-webdriver saucelabs


【解决方案1】:

以下代码适用于 chrome,它会禁用 flash 并将默认下载目录设置为不同的文件夹。

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

调用它:

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

【讨论】:

    猜你喜欢
    • 2014-02-05
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多