Reputation: 2484
When I take a screenshot using Selenium Firefox Webdriver (yes, Firefox has flash plugin) it doesn't show the flash object. It shows merely a white box instead. Is there something I must do / install?
I'm using this code:
from selenium import webdriver
def webshot(url, filename):
browser = webdriver.Firefox()
browser.get(url)
browser.save_screenshot(filename)
browser.quit()
Upvotes: 7
Views: 4061
Reputation: 2484
I fix the problem by following nonshatter's advice. I was screenshotting external pages, so I had to change wmode to "transparent" at runtime. Therefore, I needed to change all the EMBED and OBJECT using javascript. I found this nice script: http://www.onlineaspect.com/2009/08/13/javascript_to_fix_wmode_parameters/
So I simply made a script to execute that and uploaded to "mysite.com/myscript.js" and now the working script 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 scanning the javascript, it should work for nearly any flash case. I've only done a few tests, but I can at least verify that it works when screenshotting youtube pages with video playing.
Upvotes: 3
Reputation: 3517
In order 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 webpage you're trying to screenshot.
To edit an existing HTML page, add the WMODE parameters to the HTML code.
Add the following parameter to the OBJECT tag:
<param name="wmode" value="transparent">
Cheers, ns
Upvotes: 4