使用 Selenium 和 Webdriver 截取 Flash 对象的屏幕截图
当我使用 Selenium Firefox Webdriver(是的,Firefox 有 flash 插件)截取屏幕截图时,它不显示 flash 对象。它仅显示一个白色框。有什么我必须做/安装的吗?
我正在使用这段代码:
from selenium import webdriver
def webshot(url, filename):
browser = webdriver.Firefox()
browser.get(url)
browser.save_screenshot(filename)
browser.quit()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使其正常工作,我必须使用 wmode=transparent 属性。但显然,这取决于您是否可以编辑您要截图的网页的源代码。
要编辑现有 HTML 页面,请将 WMODE 参数添加到 HTML 代码中。
将以下参数添加到 OBJECT 标签:
干杯,
ns
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:
Cheers,
ns
我按照nonshatter的建议解决了这个问题。我正在对外部页面进行屏幕截图,因此我必须在运行时将 wmode 更改为“透明”。因此,我需要使用 javascript 更改所有 EMBED 和 OBJECT。我发现了这个不错的脚本: http://www.onlineaspect.com/2009/08/ 13/javascript_to_fix_wmode_parameters/
所以我只是制作了一个脚本来执行它并上传到“mysite.com/myscript.js”并且现在是工作脚本:
据我通过扫描 JavaScript 得知,它应该适用于几乎所有 Flash 情况。我只做了一些测试,但我至少可以验证它在截取播放视频的 YouTube 页面时是否有效。
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:
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.