如何获得顶级浏览上下文的初始视口的大小? [英] How can I get the size of the top-level browsing context’s initial viewport?
问题描述
我正在尝试进行图像比较,并且当我使用Webdriver捕获图像时,由于以下原因,其大小与预期的不同:
"WebDriver提供了截取屏幕快照"命令以捕获顶级浏览上下文的初始视口" 根据当前的屏幕截图定义(由开放源代码项目定义),无论窗口大小如何,屏幕截图都应具有完整的DOM."
https://github.com/seleniumhq/selenium/issues/1067
我正在使用:
js = 'return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);'
通过将图像缝合在一起的想法来获得总的页面高度,但是由于上述原因,此操作不起作用.
我如何使用完整DOM"将整个页面图像缝合在一起,并为此绘制不与窗口大小相对应的元素矩形?
当前 https://github.com/seleniumhq/selenium/issues/1067在 Protractor
上下文中,问题似乎恰好相反:
Resulting image in the case of a width x height = 367 x 667 , was turned into 800x1190
@JimEvans的答案是:
在当前截图的定义下(由开源项目定义),无论窗口大小如何,截图都应为完整的DOM.但是,有两件事要注意.首先,Chrome存在一个突出的问题,即它仅创建可见视口的屏幕截图.其次,W3C WebDriver规范将屏幕快照定义为仅当前视图端口.目前还没有任何运输驱动程序实现符合规范.
因此,我们可以得出结论,直到并且除非 WebDriver
变体实现完整DOM的屏幕截图,否则无法通过当前实现的方法来实现./p>
I am trying to do image compare and when I capture images with Webdriver their sizes are different from expected because of:
"WebDriver provides the Take Screenshot command to capture the top-level browsing context’s initial viewport" "Under the current definitions for taking screenshots (as defined by the open source project), screenshots should be of the full DOM, irrespective of window size."
https://github.com/seleniumhq/selenium/issues/1067
I am using:
js = 'return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);'
to get the total page height with the idea of stitching images together, but this isn't working because of the above.
How do I work with "full DOM" to stitch together a full page image, and for that matter draw element rectangles that are not against window size?
The current WebDriver W3C Candidate Recommendation 30 November 2017
clearly mentions the following :
The Take Screenshot command takes a screenshot of the top-level browsing context’s viewport.
Hence it won't be worth to expect a screenshot of the Full DOM
through any of the compatible browser and the implementing methods.
I am not sure about any Open Source Specs where it's mentioned as :
Under the current definitions for taking screenshots (as defined by the open source project), screenshots should be of the full DOM, irrespective of window size.
Looking at https://github.com/seleniumhq/selenium/issues/1067 the issue seems just the opposite through Protractor
context where :
Resulting image in the case of a width x height = 367 x 667 , was turned into 800x1190
Though @JimEvans answer refers :
Under the current definitions for taking screenshots (as defined by the open source project), screenshots should be of the full DOM, irrespective of window size. There are two things to note, however. First, Chrome has an outstanding issue where it only creates screenshots of the visible view port. Second, the W3C WebDriver specification defines screenshots as current view port only. No currently shipping driver implementations are spec-compliant yet.
So we can conclude, until and unless the WebDriver
variants implement the screenshot of the full DOM it wouldn't be achievable through the current implemented methods.
这篇关于如何获得顶级浏览上下文的初始视口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!