使用 Python 在 Chrome Selenium 中激活 Flash

nic*_*lle 2 python selenium selenium-chromedriver

我正在使用 Selenium 和 Python 来实现一些在线相机接口。问题是我似乎无法在 Selenium 的 Chrome 中激活 Flash。

我发现问题与我接近,但没有一个解决方案有效: https://sqa.stackexchange.com/questions/30312/enable-flash-player-on-chrome-62-while-running-selenium-test

我尝试的所有参数都没有改变任何内容,我得到的只是“获取 Flash Player”链接

这是我的代码:

chrome_options = Options()

prefs = {
"profile.default_content_setting_values.plugins" : "1",
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash- 
player" : "1",
"PluginsAllowedForUrls": "ADRESS" 
//The player is in a frame, I tried to pass both the host and the framed page
 }

chrome_options.add_argument("--disable-web-security")
chrome_options.add_argument("--allow-running-insecure-content")

chrome_options.add_experimental_option("prefs",prefs)

driver = webdriver.Chrome(chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)

谢谢

Ben*_*Ben 8

我找到了解决这个问题的方法。首先,您进入 Chrome 中特定 URL 的设置页面。然后您必须按 Tab 键 25 次才能进入闪光灯设置的下拉菜单。按空格键打开下拉菜单,然后按“a”移动到“允许”选项,“a”是因为它无法与箭头键一起使用。

这可能不是最好的解决方案,但它对我有用。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("chrome://settings/content/siteDetails?site=https%3A%2F%2Fwww.YOUR-URL.com")

actions = ActionChains(driver)
actions = actions.send_keys(Keys.TAB * 25)
actions = actions.send_keys(Keys.SPACE)
actions = actions.send_keys("a")
actions = actions.send_keys(Keys.ENTER)
actions.perform()
Run Code Online (Sandbox Code Playgroud)

这是一个非常简单的解决方案,我希望我的回答有用。

  • https://x.com/browserdotsys/status/1763337599081455865?s=20 (3认同)