在Chrome中停用Flash

时间:2014-11-30 06:32:15

标签: google-chrome testing selenium selenium-webdriver flash

我们的一个内部应用程序在页面上有一个flash对象。当浏览器中没有可用/安装的Flash插件时,我需要测试一个极端情况:既不是内部(pepperflash),也不是系统范围的adobe flash player插件

根据List of Chromium Command Line Switches文档页面,有一个相关的命令行开关:

  

--disable-bundled-ppapi-flash - 禁用捆绑的PPAPI版本的Flash。

但是,这只会关闭pepperflash内部的chrome插件。

根据How to run Chrome/Firefox with disabled flash plugin from watir script?主题,还有--disable-internal-flash切换,但它也与Chrome的内部Flash插件相关。

Browserstack's documentation建议遵循原则"断头台是最好的头皮屑治疗" 并使用--disable-plugins开关禁用所有插件:

  

要在Chrome中停用Flash,请创建chromeOptions功能   将--disable-plugins参数传递给该功能。

有没有办法在不停用Chrome中的所有插件的情况下禁用所有Flash插件?


例如,最好列出所有需要关闭的插件:

plugins.disabled: ['Adobe Flash Player', 'pepperflash']

3 个答案:

答案 0 :(得分:4)

找到它,有an another switch告诉chrome根本不加载外部插件:

  

--disable-plugins-discovery禁用发现第三方插件。有效加载浏览器附带的附加产品   由--extra-plugin-dir和--load-plugin指定的第三方   开关。

通过合并--disable-internal-flash--disable-plugins-discovery我已经实现了禁用Chrome中的所有Flash插件。

答案 1 :(得分:2)

chrome://在Chrome 57及更高版本中不再存在插件。不幸的是,alecxe在接受的答案中提出的方法对我不起作用。

我可以通过在ChromeDriver上启用移动模拟来解决此问题。有些语言的示例代码可以在这里找到:https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation

上页的java示例代码:

Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Google Nexus 5");

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);

您还可以指定自己的屏幕分辨率,像素比率甚至userAgent。

Map<String, Object> deviceMetrics = new HashMap<String, Object>();
deviceMetrics.put("width", 1920);
deviceMetrics.put("height", 1080);
deviceMetrics.put("pixelRatio", 1.0);

Map<String, Object> mobileEmulation = new HashMap<String, Object>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);

这也适用于RemoteWebDriver。

答案 2 :(得分:1)

要禁用Flash Player,请键入:

chrome:plugins

进入您的网址栏。在那里,您将看到所有插件的列表,包括Flash Player。按下禁用的按钮,你就可以了!