Selenium Webdriver take screenshot of viewport only

前端 未结 2 617
情话喂你
情话喂你 2021-01-21 21:54

I only need screenshots of the current viewport, particularly respecting the scroll position. Basically what the current Chrome driver does.

From what I\'ve read it seem

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 22:38

    There are two competing definitions of "screenshot" when dealing with 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. 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.

    The W3C WebDriver specification, on the other hand, defines screenshots to be of the current view port only. 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. 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. 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. 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.

    At present, you'll need to use a tool external to WebDriver to obtain view-port-only screenshots for IE and Firefox.

提交回复
热议问题