硒火狐司机采取窗口截图(不是全屏) [英] Selenium firefox driver take window screenshot(not fullscreen)

查看:170
本文介绍了硒火狐司机采取窗口截图(不是全屏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完整的Python脚本,用于使用selenium和FF驱动程序(windows)截取网页截图。

这个脚本取得了整个页面的截图,而不是让我们说1024x768,这个过程很慢。这里是我的代码:

  driver = webdriver.Firefox()
driver.set_window_size(1024,768)
driver.get(url)
driver.get_screenshot_as_file(%s /%s.png%(screen_dir,o.netloc))
driver.close()

有关如何使selenium / firefox获取屏幕截图而不是完整页面的想法?

感谢!

解决方案

即使它的一部分是不可见的,它也会从顶部到底部截取一个完整的页面。这实际上不是它应该如何工作的规范



Chrome 只会显示可见区域/视口的屏幕截图。切换到它。


I have a fully working Python script for taking screenshots of webpages using selenium and the FF driver(windows).

The script is taking full page screenshots instead of let's say 1024x768, which make the process slow. Here is my code:

    driver = webdriver.Firefox()
    driver.set_window_size(1024,768)
    driver.get(url)
    driver.get_screenshot_as_file("%s/%s.png"%(screen_dir,o.netloc))
    driver.close()

Any ideas on how to make selenium/firefox take above the fold screenshots and not full page?

Thanks!

解决方案

This is how the "take screenshot" functionality is working in Firefox - it would take a screenshot of a complete page from top to bottom even if part of it is not visible. This is actually not how it supposed to work by the specification.

Chrome would take a screenshot of the visible area / viewport only. Switch to it.

这篇关于硒火狐司机采取窗口截图(不是全屏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆