允许Chrome 69中的Flash内容通过chromedriver运行

doc*_*rue 6 selenium google-chrome webdriver selenium-chromedriver selenium-webdriver

有没有人知道如何在Chrome 69中启用Flash插件.我使用chromedriver 2.41和java selenium绑定.我试过了

prefs.put("profile.default_content_setting_values.plugins", 1);
prefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
Run Code Online (Sandbox Code Playgroud)

但没有运气.我还尝试将chrome配置文件首选项与特定网站的不允许/允许的Flash进行比较,然后尝试使用:

            Map<String, Object> site = new HashMap<>();
            Map<String, Object> values = new HashMap<>();
            Map<String, Object> setting = new HashMap<>();
            setting.put("flashPreviouslyChanged", true);
            values.put("last_modified", "13180613213099316");
            values.put("setting", setting);
            site.put("http://my.site,*", values);
            prefs.put("profile.content_settings.exceptions.flash_data", site);
Run Code Online (Sandbox Code Playgroud)

但它不会起作用.

我也尝试使用指定的配置文件运行

options.addArguments("user-data-dir=" + profileDir);
Run Code Online (Sandbox Code Playgroud)

但由于此白名单设置在Chrome 69中变为"短暂",因此也无效.

有没有方法可以在支持闪存的Chrome中运行我的自动化?

doc*_*rue 3

谢谢大家的解答。

我终于找到了解决方案。为了从 Chrome 69 开始以编程方式启用 Flash,我们必须做两件事:

  1. 禁用临时 Flash 权限(以启用允许 Flash 站点的列表)和
  2. 将所有站点添加到该列表中。

Java 上请参见以下代码:

ChromeOptions options = new ChromeOptions();
// disable ephemeral flash permissions flag
options.addArguments("--disable-features=EnableEphemeralFlashPermission");
Map<String, Object> prefs = new HashMap<>();
// Enable flash for all sites for Chrome 69
prefs.put("profile.content_settings.exceptions.plugins.*,*.setting", 1);

options.setExperimentalOption("prefs", prefs);
nestedDriver = new ChromeDriver(options);
Run Code Online (Sandbox Code Playgroud)