Selenium 允许通过chromedriver运行Chrome 69中的闪存内容
有人知道如何在Chrome69中启用Flash插件吗。 我将chromedriver 2.41与java selenium绑定一起使用。 我试过了Selenium 允许通过chromedriver运行Chrome 69中的闪存内容,selenium,google-chrome,selenium-webdriver,webdriver,selenium-chromedriver,Selenium,Google Chrome,Selenium Webdriver,Webdriver,Selenium Chromedriver,有人知道如何在Chrome69中启用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_setting
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);
但是,由于这个白名单设置在Chrome69中变得“短暂”,它也不会工作
有什么方法可以在支持flash的Chrome中运行我的自动化吗?在运行测试之前,我通过进入网站的设置并执行selenium操作来处理这个问题,例如:
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();
}
最近发布的Chrome 69不允许通过
chrome://settings/content/flash
与以前版本的Flash Player一样。但是,通过单击位置栏左侧的锁定图标,然后选择站点设置,然后启用Flash Player,可以临时启用当前SESION的URL
此策略强制Flash Player的用户在每个会话中重新配置其权限设置,从而降低了使用Flash Player的便利性。这显然是故意的
幸运的是,Microsoft Edge浏览器没有此策略。像Chrome一样,Edge运行Flash Player。但是,与Chrome不同,它保留了权限设置,不会给用户带来不便。遵循以下步骤:
这将不会要求在Chrome 69中运行Flash Player进行进一步的会话。谢谢大家的回答 我终于找到了解决办法。为了从Chrome 69开始以编程方式启用flash,我们必须做两件事:
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);
ChromeOptions选项=新的ChromeOptions();
//禁用临时闪存权限标志
options.addArguments(“--disable features=enablephemeralFlashPermission”);
Map prefs=新的HashMap();
//为Chrome 69的所有站点启用闪存
prefs.put(“profile.content\u settings.exceptions.plugins.*,*.setting”,1);
选项。设置实验选项(“prefs”,prefs);
nestedDriver=新的ChromeDriver(选项);
我的C#解决方案
使用带有链接的@RodolphoSilva回答: 1-输入链接:chrome://flags/#enable-临时闪存权限 2-更改为“禁用” 3-单击“立即重新启动”按钮 4-输入链接:chrome://settings/content/flash?search=flash 5-现在您可以添加或阻止站点以使用flash
@非常感谢你的回答 如果其他人需要它,下面介绍如何在量角器配置中执行相同的操作:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-features=EnableEphemeralFlashPermission'],
prefs: {
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
}
},
}
ChromeOptions选项=新的ChromeOptions();
options.addArguments(“--disable features=enablephemeralFlashPermission”);
Map prefs=新的HashMap();
prefs.put(“profile.content\u settings.exceptions.plugins.*,per\u resource.adobeflashplayer”,1);
选项。设置实验选项(“prefs”,prefs);
WebDriver=新的ChromeDriver(选项);
获取(“某个url”);
鉴于Chrome 71中的标志--disable features=enableMephemeralFlashPermission已被删除,这严重削弱了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之后调用helper
driver = new ChromeDriver(options);
new FlashPolicyHelper(driver).addSite("https://your.site").addSite("https://another.site");
感谢@JohnoCrawford,我通过引用他的java代码编写了一个python代码
从urllib导入quote作为url添加quote plus
从URL解析导入URL拆分
从selenium.webdriver.common.by作为WebBy导入
从selenium.webdriver.support.ui导入选择为WebSelect
def allow_闪存(驱动程序,url):
定义基本url(url):
如果url.find(“:/”)==-1:
url=“http://{}”。格式(url)
url=URLSPILT(url)
返回“{}://{}”。格式(url.scheme,url.netloc)
def_shadow_root(驱动程序、元素):
返回驱动程序。执行_脚本(“返回参数[0]。shadowRoot”,元素)
基本url=\u基本url(url)
驱动程序。获取(“chrome://settings/content/siteDetails?site={}.格式(url(基url)))
root1=driver.find_元素(WebBy.TAG_名称,“设置ui”)
shadow\u root1=\u shadow\u root(驱动程序,root1)
root2=shadow\u root1.find\u元素(WebBy.ID,“容器”)
root3=root2.find_元素(WebBy.ID,“main”)
shadow\u root3=\u shadow\u root(驱动程序,root3)
root4=shadow\u root3.find\u元素(WebBy.CLASS\u名称,“显示子页面”)
shadow\u root4=\u shadow\u root(驱动程序,root4)
root5=shadow\u root4.find\u元素(WebBy.ID,“advancedPage”)
root6=root5.find_元素(WebBy.TAG_名称,“设置隐私页面”)
shadow\u root6=\u shadow\u root(驱动程序,root6)
root7=shadow\u root6.find\u元素(WebBy.ID,“pages”)
root8=root7.find_元素(WebBy.TAG_名称,“设置子页面”)
root9=root8.find_元素(WebBy.TAG_名称,“站点详细信息”)
shadow\u root9=\u shadow\u root(驱动程序,root9)
root10=shadow_root9.find_元素(WebBy.ID,“plugins”)#Flash
shadow\u root10=\u shadow\u root(驱动程序,root10)
root11=shadow\u root10.find\u元素(WebBy.ID,“权限”)
WebSelect(root11)。按值选择(“允许”)
因为我看到这里有很多方法不适用于Chrome 71,所以我想与大家分享我正在使用的C#解决方案:
ChromeOptions ChromeOptions=新的ChromeOptions();
List allowFlashUrls=新列表(){
“*.testing1.com”,
“*.testing2.com”,
};
AddUserProfilePreference(“profile.managed_plugins_allowed_for_url”,config.ChromeConfig.AllowFlashUrls);
镀铬器镀铬器镀铬器
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-features=EnableEphemeralFlashPermission");
Map<String, Object> prefs = new HashMap<>();
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player",1);
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
driver.get("some url");
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);
}
}
driver = new ChromeDriver(options);
new FlashPolicyHelper(driver).addSite("https://your.site").addSite("https://another.site");
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
def add_flash_site(driver, web_url):
def expand_root_element(element):
return driver.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")
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")
*** 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!!
def add_flash_site(driver, web_url):
def expand_root_element(element):
return driver.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.TAG_NAME, "settings-privacy-page")
shadow_root5 = expand_root_element(root5)
root6 = shadow_root5.find_element(By.ID, "pages")
root7 = root6.find_element(By.TAG_NAME, "settings-subpage")
root8 = root7.find_element(By.TAG_NAME, "site-details")
shadow_root8 = expand_root_element(root8)
root9 = shadow_root8.find_element(By.ID, "plugins")
shadow_root9 = expand_root_element(root9)
root10 = shadow_root9.find_element(By.ID, "permission")
Select(root10).select_by_value("allow")
root5 = shadow_root4.find_element(By.ID, "advancedPage")
root5 = shadow_root4.find_element(By.ID, "basicPage")