Take a flash shot using Selenium using Webdriver

When I take a screenshot using Selenium Firefox Webdriver (yes, Firefox has a Flash plugin), it does not show the Flash object. Instead, only a white box is displayed. Do I have to do / install something?

I am using this code:

from selenium import webdriver def webshot(url, filename): browser = webdriver.Firefox() browser.get(url) browser.save_screenshot(filename) browser.quit() 
+6
source share
2 answers

To get this working, I had to use the wmode = transparent attribute. But, obviously, this will depend on whether you can edit the source of the web page that you are trying to capture from the screen.

To modify an existing HTML page, add WMODE parameters to the HTML code.

Add the following parameter to the OBJECT tag:

  <param name="wmode" value="transparent"> 

Cheers, ns

+4
source

I am fixing this issue following insecure tips. I took screenshots of external pages, so I had to change wmode to transparent at runtime. So I needed to change all EMBED and OBJECT using javascript. I found this nice script: http://www.onlineaspect.com/2009/08/13/javascript_to_fix_wmode_parameters/

So I just made a script to execute it and uploaded it to "mysite.com/myscript.js", and now the working script is here:

 from selenium import webdriver script = ''' var s = document.createElement('script'); s.src = 'http://mysite.com/myscript.js'; document.body.appendChild(s); ''' def webshot(url, filename): browser = webdriver.Firefox() browser.get(url) browser.execute_script(script) browser.save_screenshot(filename) browser.quit() 

As far as I can tell from javascript validation, it should work for almost any flash drive. I tested only a few tests, but at least I can make sure that it works when screening YouTube pages with video playback.

+3
source

Source: https://habr.com/ru/post/898558/


All Articles