简体   繁体   English

Selenium Webdriver仅获取视口的屏幕截图

[英]Selenium Webdriver take screenshot of viewport only

I only need screenshots of the current viewport, particularly respecting the scroll position. 我只需要当前视口的屏幕截图,尤其要注意滚动位置。 Basically what the current Chrome driver does. 基本上是当前Chrome驱动程序的功能。

From what I've read it seems this should be entirely possible, but for some reason the screenshot commands always strive to take a full document screenshot. 从我所阅读的内容看来,这应该是完全有可能的,但是由于某些原因,screenshot命令始终努力获取完整的文档截图。 In fact the IE driver takes multiple viewport shots and then stitches them together. 实际上,IE驱动程序会拍摄多个视口镜头,然后将它们缝合在一起。

I'm using the Ruby webdriver, and I can't see anyway to take a screenshot of just the viewport. 我使用的是Ruby Webdriver,无论如何我都看不到仅截取视口的屏幕截图。 Is it possible? 可能吗?

There are two competing definitions of "screenshot" when dealing with WebDriver. 在处理WebDriver时,有两个相互竞争的“屏幕快照”定义。 The first is the definition used by the open-source project, where a screenshot is defined to be an image of the entire DOM of the loaded page. 第一个是开放源代码项目使用的定义,其中屏幕快照定义为加载页面的整个DOM的图像。 In this case, both the IE driver and the Firefox driver are doing the correct thing as defined by the project since 2010. The Chrome implementation of WebDriver is incorrect in returning an image of only the visible view port. 在这种情况下,自2010年以来,IE驱动程序和Firefox驱动程序都在执行项目定义的正确操作。WebDriver的Chrome实施错误地返回了仅可见端口的图像。

The W3C WebDriver specification , on the other hand, defines screenshots to be of the current view port only. 另一方面, W3C WebDriver规范将屏幕快照定义为仅当前视口。 This is at odds with the current open-source project's driver implementations (IE and Firefox), and can be expected to change in the future. 这与当前的开放源代码项目的驱动程序实现(IE和Firefox)不一致,并且可以预期在将来发生变化。 Once the specification has attained "Candidate Recommendation" status, those drivers are likely to be updated. 规范达到“候选推荐”状态后,可能会更新那些驱动程序。

As an aside, it should be noted that the IE driver in no way uses a "scroll-and-stitch" method to create its screenshots. 顺便说一句 ,应该注意的是,IE驱动程序绝不使用“滚动拼接”方法来创建其屏幕截图。 It does resize the browser window large enough to display the entire DOM, as calculated at the moment the screenshot is requested, and take an image of that. 确实将浏览器窗口调整为足以显示整个DOM的大小,以显示整个DOM(如在请求屏幕快照时计算的那样),并拍摄图像。 However, please note that there are issues with IE 10 and 11 in producing these full-DOM screenshots depending on the bit-ness of your operating system and of the IEDriverServer executable you're using. 但是,请注意,根据操作系统和所使用的IEDriverServer可执行文件的位数 ,生成完整的DOM屏幕截图时,IE 10和11存在问题。

At present, you'll need to use a tool external to WebDriver to obtain view-port-only screenshots for IE and Firefox. 目前,您需要使用WebDriver外部的工具来获取IE和Firefox的仅查看端口的屏幕​​截图。

This is a frequently changing issue.. 这是一个经常更改的问题。

AFAIK right now Chrome- and IEDriver both capture screenshots of the viewport only, while FFDriver captures a full-page screenshot (FF will change this in the future). AFAIK现在,Chrome-和IEDriver都仅捕获视口的屏幕截图,而FFDriver则捕获全页面的屏幕截图(FF将来会对此进行更改)。 See also my answer to this question . 另请参阅我对这个问题的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Ruby在Selenium Webdriver中使用屏幕快照名称中包含日期和时间的屏幕快照? - How to take screenshot in selenium webdriver with ruby with date and time included in screenshot name? 如何在 Ruby 中使用 selenium-webdriver/capybara 截取完整浏览器页面及其元素的屏幕截图? - How to take a screenshot of a full browser page and its elements using selenium-webdriver/capybara in Ruby? Selenium或Watir Webdriver,如何保存调整大小的截图? - Selenium or Watir Webdriver, how to save resized screenshot? Ruby + Selenium-执行每个步骤后截屏 - Ruby + Selenium - Take a screenshot with each step executed 使用selenium-webdriver / rc rails整个屏幕的ScreenShot - ScreenShot of entire webpage using selenium-webdriver/ rc rails 如何使用Ruby Selenium Webdriver进行操作系统级别的屏幕截图 - How to take an OS level screen capture using ruby selenium webdriver 拍摄场景失败截图 - Take a scenario failure screenshot 谁能建议如何使用 ruby​​ selenium 截取整个网页的屏幕截图? - Can anyone suggest how to take screenshot of full webpage using ruby selenium? 如何使用Selenium Webdriver在页面上查找仅可见元素? - How can I find visible only elements on a page with Selenium Webdriver? 使用watir扩展元素截图截屏 - Take screenshot using watir extension element screenshot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM