Allow Flash content in Chrome 69 running via chromedriver
Given the flag --disable-features=EnableEphemeralFlashPermission
has been removed in Chrome 71 which severely cripples Flash test automation I would like to share our solution.
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);
}
}
The helper should be called after instantiating the ChromeDriver.
driver = new ChromeDriver(options);
new FlashPolicyHelper(driver).addSite("https://your.site").addSite("https://another.site");
Thanks everyone for answers.
I finally have found the solution. In order to enable flash progrmatically since Chrome 69 we have to do 2 things:
- Disable Ephemeral Flash Permissions (to enable list of allowed for Flash sites) and
- Add all sites to that list.
See the following code on 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);
Follow these steps:
- Input this URL in Chrome: chrome://flags/
- On search inputbox, digit: ephemeral flash
- Choose "disabled" option.
This will not ask to run Flash Player for further sessions in Chrome 69.