有人知道如何在Chrome 69中启用Flash插件。 我将chromedriver 2.41与Java硒绑定一起使用。 我已经尝试过
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);
但是没有运气。 我还尝试将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);
但是它不能正常工作。
我还尝试使用通过以下方式指定的配置文件运行
options.addArguments("user-data-dir=" + profileDir);
但是由于此白名单设置在Chrome 69中变为“临时”,因此它也将不起作用。
是否有任何方法可以在具有Flash支持的Chrome中运行自动化?
答案 0 :(得分:3)
请按照以下步骤操作:
这不会要求在Chrome 69中运行Flash Player进行进一步的会话。
答案 1 :(得分:2)
感谢大家的回答。
我终于找到了解决方案。为了从Chrome 69开始以编程方式启用闪光灯,我们必须做两件事:
在Java上查看以下代码:
mSubscription.add(
glideSingle
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<GlideRequest<Drawable>>() {
@Override
public void accept(GlideRequest<Drawable> drawableGlideRequest) throws Exception {
RequestOptions backgroundTransformOptions = new RequestOptions()
.transforms(
new CenterCrop(),
new BlurTransformation(60),
new ColorFilterTransformation(
ContextCompat.getColor(MainActivity.this, R.color.colorBackgroundOverlay))
);
drawableGlideRequest
.into(mAlbumArt);
drawableGlideRequest
.apply(backgroundTransformOptions)
.into(mMainBackground);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
}
})
);
答案 2 :(得分:2)
鉴于Chrome 71中的标记--disable-features=EnableEphemeralFlashPermission
已被删除,这严重削弱了Flash测试自动化,我想分享我们的解决方案。
public class FlashPolicyHelper {
private final ChromeDriver driver;
public FlashPolicyHelper(ChromeDriver driver) {
this.driver = driver;
}
public FlashPolicyHelper addSite(String site) {
this.driver.get("chrome://settings/content/siteDetails?site=" + site);
WebElement root1 = driver.findElement(By.tagName("settings-ui"));
WebElement shadowRoot1 = expandRootElement(root1);
WebElement root2 = shadowRoot1.findElement(getByIdentifier("id=container"));
WebElement main = root2.findElement(getByIdentifier("id=main"));
WebElement shadowRoot3 = expandRootElement(main);
WebElement shadowRoot4 = shadowRoot3.findElement(getByIdentifier("class=showing-subpage"));
WebElement shadowRoot5 = expandRootElement(shadowRoot4);
WebElement shadowRoot6 = shadowRoot5.findElement(getByIdentifier("id=advancedPage"));
WebElement shadowRoot7 = shadowRoot6.findElement(By.tagName("settings-privacy-page"));
WebElement shadowRoot8 = expandRootElement(shadowRoot7);
WebElement shadowRoot9 = shadowRoot8.findElement(getByIdentifier("id=pages"));
WebElement shadowRoot10 = shadowRoot9.findElement(By.tagName("settings-subpage"));
WebElement shadowRoot11 = shadowRoot10.findElement(By.tagName("site-details"));
WebElement shadowRoot12 = expandRootElement(shadowRoot11);
WebElement shadowRoot13 = shadowRoot12.findElement(By.id("plugins"));
WebElement shadowRoot14 = expandRootElement(shadowRoot13);
new Select(shadowRoot14.findElement(By.id("permission"))).selectByValue("allow");
return this;
}
private By getByIdentifier(String identifier) {
String[] identifiers = identifier.split("=");
return identifiers[0].equals("id") ? By.id(identifiers[1]) :
By.className(identifiers[1]);
}
private WebElement expandRootElement(WebElement element) {
return (WebElement) driver.executeScript("return arguments[0].shadowRoot",element);
}
}
应在实例化ChromeDriver之后调用帮助程序。
driver = new ChromeDriver(options);
new FlashPolicyHelper(driver).addSite("https://your.site").addSite("https://another.site");
答案 3 :(得分:1)
最近发布的Chrome 69不允许像以前版本的Flash Player一样通过chrome://settings/content/flash
永久添加(启用)网站(URL)。但是,可以通过单击位置栏左侧的锁定图标,临时暂时启用当前会话的URL,然后选择站点设置,然后启用Flash Player
此策略会强制Flash Player用户在每个会话中重新配置其权限设置,这使得使用Flash Player的权限变得不太方便。这显然是设计使然。
幸运的是, Microsoft Edge 浏览器没有具有此策略。像Chrome一样,Edge可以运行Flash Player。但是,与Chrome不同,它会保留权限设置,不会不会给用户带来不便。
答案 4 :(得分:1)
感谢@JohnoCrawford,我通过引用他的Java代码编写了python代码。
from urllib import quote_plus as url_quoteplus
from urlparse import urlsplit
from selenium.webdriver.common.by import By as WebBy
from selenium.webdriver.support.ui import Select as WebSelect
def allow_flash(driver, url):
def _base_url(url):
if url.find("://")==-1:
url = "http://{}".format(url)
urls = urlsplit(url)
return "{}://{}".format(urls.scheme, urls.netloc)
def _shadow_root(driver, element):
return driver.execute_script("return arguments[0].shadowRoot", element)
base_url = _base_url(url)
driver.get("chrome://settings/content/siteDetails?site={}".format(url_quoteplus(base_url)))
root1 = driver.find_element(WebBy.TAG_NAME, "settings-ui")
shadow_root1 = _shadow_root(driver, root1)
root2 = shadow_root1.find_element(WebBy.ID, "container")
root3 = root2.find_element(WebBy.ID, "main")
shadow_root3 = _shadow_root(driver, root3)
root4 = shadow_root3.find_element(WebBy.CLASS_NAME, "showing-subpage")
shadow_root4 = _shadow_root(driver, root4)
root5 = shadow_root4.find_element(WebBy.ID, "advancedPage")
root6 = root5.find_element(WebBy.TAG_NAME, "settings-privacy-page")
shadow_root6 = _shadow_root(driver, root6)
root7 = shadow_root6.find_element(WebBy.ID, "pages")
root8 = root7.find_element(WebBy.TAG_NAME, "settings-subpage")
root9 = root8.find_element(WebBy.TAG_NAME, "site-details")
shadow_root9 = _shadow_root(driver, root9)
root10 = shadow_root9.find_element(WebBy.ID, "plugins") # Flash
shadow_root10 = _shadow_root(driver, root10)
root11 = shadow_root10.find_element(WebBy.ID, "permission")
WebSelect(root11).select_by_value("allow")
答案 5 :(得分:0)
在运行测试之前,我进入了网站设置并进行了如下硒操作:
public void SetFlashForURL (string yourWebsiteURL) {
driver.Navigate().GoToUrl(string.Format("chrome://settings/content/siteDetails?site={0}", yourWebsiteURL));
Thread.Sleep(1000);
Actions actions = new Actions(driver);
if (yourWebsiteURL.Contains("https"))
{
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
}
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Tab);
actions.SendKeys(OpenQA.Selenium.Keys.Down);
actions.Build().Perform();
}
答案 6 :(得分:0)
我的C#解决方案
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--disable-features=EnableEphemeralFlashPermission");
chromeOptions.AddUserProfilePreference(
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
var capability = (DesiredCapabilities)chromeOptions.ToCapabilities();
答案 7 :(得分:0)
使用@RodolphoSilva答案和链接:
1-输入链接: chrome:// flags /#enable-ephemeral-flash-permission
2-更改为“ 已禁用”
3-单击“ 立即重新发布”按钮
4-输入链接: chrome:// settings / content / flash?search = flash
5-现在您可以添加或阻止网站以使用Flash
@RodolphoSilva-非常感谢您的出色回答!
答案 8 :(得分:0)
万一其他人需要它,这是在量角器配置中执行相同操作的方法:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-features=EnableEphemeralFlashPermission'],
prefs: {
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
}
},
}
答案 9 :(得分:0)
int gcd(int a, int b){
/** sanity checks */
if((a==0) || (b==0))
return 0;
/* few more obvious checks */
if( a % b == 0 )
return b;
if( b % a == 0 )
return a;
/* Real Logic */
while( (a != 0) && (b != 0) ){
if (abs(a)>abs(b)){
a = abs(a) % abs(b);
}
else if(abs(b) > abs(a) ){
b = abs(b) % abs(a);
}
}
/* Final results */
return (a == 0) ? b : a;
}
答案 10 :(得分:0)
由于我看到许多方法不适用于Chrome 71,因此我想在我正在使用的C#中共享解决方案:
ChromeOptions chromeOptions = new ChromeOptions();
List<string> allowFlashUrls = new List<string>() {
"*.testing1.com",
"*.testing2.com",
};
chromeOptions.AddUserProfilePreference("profile.managed_plugins_allowed_for_urls", config.ChromeConfig.AllowFlashUrls);
ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
// Then run your test using chromeDriver
通过设置profile.managed_plugins_allowed_for_urls
将强制Chrome浏览器在allowFlashUrls
列表中声明的域中允许运行Flash。未经测试,但应该通过添加http://*
和https://
允许Flash到所有站点,以允许Flash列表。
答案 11 :(得分:0)
Chrome 74的Python3版本。从上述@JohnoCrawford的Java版本转换而来。
def add_flash_site(drv, web_url):
def expand_root_element(element):
return drv.execute_script("return arguments[0].shadowRoot", element)
driver.get("chrome://settings/content/siteDetails?site=" + web_url)
root1 = driver.find_element(By.TAG_NAME, "settings-ui")
shadow_root1 = expand_root_element(root1)
root2 = shadow_root1.find_element(By.ID, "container")
root3 = root2.find_element(By.ID, "main")
shadow_root3 = expand_root_element(root3)
root4 = shadow_root3.find_element(By.CLASS_NAME, "showing-subpage")
shadow_root4 = expand_root_element(root4)
root5 = shadow_root4.find_element(By.ID, "advancedPage")
root6 = root5.find_element(By.TAG_NAME, "settings-privacy-page")
shadow_root6 = expand_root_element(root6)
root7 = shadow_root6.find_element(By.ID, "pages")
root8 = root7.find_element(By.TAG_NAME, "settings-subpage")
root9 = root8.find_element(By.TAG_NAME, "site-details")
shadow_root9 = expand_root_element(root9)
root10 = shadow_root9.find_element(By.ID, "plugins")
shadow_root10 = expand_root_element(root10)
root11 = shadow_root10.find_element(By.ID, "permission")
Select(root11).select_by_value("allow")
答案 12 :(得分:0)
使用robotframework在chromedriver中启用Flash
积分:@BaiJiFeiLong
将以下代码另存为flash_helper.py
from robot.libraries.BuiltIn import BuiltIn
from selenium.webdriver.common.by import By as WebBy
from selenium.webdriver.support.ui import Select as WebSelect
def allow_flash(url):
seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary')
driver = seleniumlib.driver
def _shadow_root(driver, element):
return driver.execute_script("return arguments[0].shadowRoot", element)
driver.get("chrome://settings/content/siteDetails?site={}".format(url))
root1 = driver.find_element(WebBy.TAG_NAME, "settings-ui")
shadow_root1 = _shadow_root(driver, root1)
root2 = shadow_root1.find_element(WebBy.ID, "container")
root3 = root2.find_element(WebBy.ID, "main")
shadow_root3 = _shadow_root(driver, root3)
root4 = shadow_root3.find_element(WebBy.CLASS_NAME, "showing-subpage")
shadow_root4 = _shadow_root(driver, root4)
root5 = shadow_root4.find_element(WebBy.ID, "advancedPage")
root6 = root5.find_element(WebBy.TAG_NAME, "settings-privacy-page")
shadow_root6 = _shadow_root(driver, root6)
root7 = shadow_root6.find_element(WebBy.ID, "pages")
root8 = root7.find_element(WebBy.TAG_NAME, "settings-subpage")
root9 = root8.find_element(WebBy.TAG_NAME, "site-details")
shadow_root9 = _shadow_root(driver, root9)
root10 = shadow_root9.find_element(WebBy.ID, "plugins") # Flash
shadow_root10 = _shadow_root(driver, root10)
root11 = shadow_root10.find_element(WebBy.ID, "permission")
WebSelect(root11).select_by_value("allow")
在机器人框架中将上述方法用作关键字
将以下代码另存为test.robot
*** Settings ***
Library SeleniumLibrary
Library flash_helper.py
*** Test Case ***
Allow Flash In Chrome
Open Browser https://www.google.com chrome
# go to chrome settings and enable flash
${CURRENT_URL} Get Location
Allow Flash ${CURRENT_URL}
# revert to previous page
Go To ${CURRENT_URL}
# now Flash is enabled in chrome!!
答案 13 :(得分:0)
由于在Chrome 71+版本中不能再禁用nil
,因此以下是@JohnoCrawford代码的稍作修改的版本,适用于Chrome 81:
EnableEphemeralFlashPermission
答案 14 :(得分:0)
我与用户BaiJiFeiLong的答案相同
但是我发现我不得不改变这一行:
root5 = shadow_root4.find_element(By.ID, "advancedPage")
收件人:
root5 = shadow_root4.find_element(By.ID, "basicPage")
因为原始行返回了NoSuchElement错误。