Webdriver.io 为 selenium-standalone 启用 flash

Webdriver.io enable flash for selenium-standalone

我正在使用 webdriver.ioselenium 在 node.js 上编写验收测试具有最新 Google Chrome 驱动程序.

的独立服务器

我需要检查 flash 元素是否可点击,但浏览器一直显示 "Restart Chrome to enable Adobe Flash Player"。

我看过 article that shows how to make Chrome driver to see custom profile on local machine, but I can't understand how to use this with my standalone server, since it has poor examples 的配置。 您能否在 webdriver.io 中解释为 selenium 独立服务器启用 Adob​​e flash 播放器的正确方法?

这很容易。您需要创建一个自定义配置文件,您将始终使用它来加载 chrome。然后像手动配置浏览器一样配置浏览器。这意味着为 Flash 排除网站。加载一些扩展或任何你想预配置的东西。使用此代码你可以做到

// setup browser
var options = {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['user-data-dir=C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Profile 21v69',
'--lang=en']
} //  chromeOptions: {
} // desiredCapabilities: {
} // options = {



var client = webdriverio.remote(options).init();

这里还有 chrome 的所有命令行命令 https://peter.sh/experiments/chromium-command-line-switches/

另一种可行的方法。可以在 chrome 配置中允许执行 Flash 插件 您需要在 wdio.conf.js 代码示例

中添加最后三个首选项
chromeOptions : {
        args: chromeArgs,
        prefs: {
            "download.default_directory": process.env.PWD +'/download',
            "profile.default_content_setting_values.plugins": 1,
            "profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
            "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1
        }
    }

希望对您有所帮助

我发现以下方法有效:

browserName: 'chrome',
 'goog:chromeOptions' : {
            args: ['enable-features=RunAllFlashInAllowMode',
                   'disable-features=EnableEphemeralFlashPermission'],
            prefs: {
                "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
                'PluginsAllowedForUrls': '/route/to/site.com'
            }
        }

使用临时模式将创建一个允许首选项生效的临时配置文件:

https://developer.chrome.com/extensions/contentSettings https://support.google.com/chrome/a/answer/3538894?hl=en

'goog:chromeOptions' 是从 selenium 3.8 github.com/elgalu/docker-selenium/issues/201 –

开始引入的

您可以打开作为 JSON blob 的配置文件并查看添加在 profile.content_settings.exceptions.plugins 和 profile.content_settings.exceptions.flash_data 的站点。