Search code examples
pythonseleniumflashui-automationpyvirtualdisplay

How to automate the activation of Flash plug-in using selenium firefox geckodriver?


When I try to open a page with flash using an automated python script with Selenium I reach the page in the picture below. And I cannot pass.

Flash Activation Page

It's a remote server running Ubuntu 16.04, without access to a monitor or a keyboard/mouse.

Python version: 3.5.2

Selenium version: 3.14.1

Geckodriver 0.26.0

Follows my code:

import pyvirtualdisplay
print ("pyvirtualdisplay Display Version: %s" % (pyvirtualdisplay.__version__))
from selenium import webdriver
print ("Selenium webdriver Version: %s" % (webdriver.__version__))

display = pyvirtualdisplay.Display(visible=0, size=(800, 600))
display.start()

profile = webdriver.FirefoxProfile()
profile.native_events_enabled = False
profile.set_preference("plugin.state.flash", 2)
profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so","true")
driver = webdriver.Firefox(profile)
driver.set_page_load_timeout(60)
url = 'https://www.ultrasounds.com/US.html'
driver.get(url)

driver.close()
driver.quit()
display.stop()
quit()

Here's the output:

Python 3.5.2 (default, Apr 16 2020, 17:47:17)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvirtualdisplay
>>> print ("pyvirtualdisplay Display Version: %s" % (pyvirtualdisplay.__version__))
pyvirtualdisplay Display Version: 0.2.4
>>> from selenium import webdriver
>>> print ("Selenium webdriver Version: %s" % (webdriver.__version__))
Selenium webdriver Version: 3.14.1
>>>
>>> display = pyvirtualdisplay.Display(visible=0, size=(800, 600))
>>> display.start()
<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1001'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1001'] oserror=None return_code=None stdout="None" stderr="None" timeout_happened=False>
>>>
>>> profile = webdriver.FirefoxProfile()
>>> profile.native_events_enabled = False
>>> profile.set_preference("plugin.state.flash", 2)
>>> profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so","true")
>>> driver = webdriver.Firefox(profile)

>>> driver.set_page_load_timeout(60)
>>> url = 'https://www.ultrasounds.com/US.html'
>>> driver.get(url)
>>>
>>>
>>> import pyautogui
>>> im1 = pyautogui.screenshot('flash_activation_page.jpg')
>>> driver.close()
>>> driver.quit()
>>> display.stop()
<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1001'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1001'] oserror=None return_code=0 stdout="" stderr="" timeout_happened=False>
>>>

Solution

  • With Firefox >= 69, you won't be able to do that:

    The setting to always activate the Adobe Flash plugin was removed in Firefox 69. See this compatibility document for details.


    Flash Player can no longer always be activated

    Published: June 15, 2019

    Categories: Plug-ins

    Releases: Firefox 69

    Description

    As part of the ongoing Flash plug-in support deprecation, Firefox 69 has removed the “Always Activate” option from the page notification dialog and the “Remember this decision” option from the Add-on Manager. It means, from now on, Firefox will ask the user every time if they want to show Flash content on a website during a browser session, and the user won’t be able to change this behaviour.

    At the time of this writing, only half of Firefox users have Flash Player installed according to Firefox Public Data Report, and the number is steadily decreasing. Given that the Flash support will be removed from Firefox and other browsers in 2020, you are strongly encouraged to make a migration plan as soon as possible if your site still relies on any Flash content including legacy video players.