【问题标题】:Activate Flash in Chrome Selenium with Python使用 Python 在 Chrome Selenium 中激活 Flash
【发布时间】:2020-04-14 12:46:59
【问题描述】:

我正在将 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)

谢谢

【问题讨论】:

标签: python selenium selenium-chromedriver


【解决方案1】:

我找到了解决此问题的方法。首先,您转到 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()

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

【讨论】:

    【解决方案2】:

    谢谢,本,

    稍微调整一下,解决方案对我有用。请在下面找到我的解决方案。

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    
    driver = webdriver.Chrome(executable_path="C:\\py\\selenium\\chrome\\chromedriver2.exe", options=options)
    
    ## Step one visit the site you want to activate flash player    
    driver.get("https://helpx.adobe.com/flash-player.html")
    
    ## Step 2  Once your page is loaded in chrome, go to the URL where lock sign is there visit the 
    ##setting page where you will see that the flash is disabled.
    
    ## step 3 copy that link and paste below
    driver.get("chrome://settings/content/siteDetails?site=https%3A%2F%2Fhelpx.adobe.com")
    
    ## below code is for you to reach to flash dialog box and change it to allow from block.
    actions = ActionChains(driver)
    actions = actions.send_keys(Keys.TAB * 12)
    actions = actions.send_keys(Keys.SPACE)
    actions = actions.send_keys("a")
    actions = actions.send_keys(Keys.ENTER)    
    actions.perform()
    
    ## This Step will bring you back to your original page where you want to load the flash
    driver.back()
    

    问候

    【讨论】:

      猜你喜欢
      • 2017-07-03
      • 2020-09-12
      • 2010-12-11
      • 2018-07-07
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      相关资源
      最近更新 更多