使用Selenium Web Driver进行页面拍摄 [英] Take a page shoot with Selenium Web Driver

查看:115
本文介绍了使用Selenium Web Driver进行页面拍摄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Selenium WebDriver截屏的问题和答案包含出色的描述如何使用Selenium Web Driver使用不同语言进行屏幕截图.

Question and answers on Take a screenshot with Selenium WebDriver contain excellent description how to take screen shot with Selenium Web Driver using different languages.

我使用Python和C#以及一组不同的浏览器驱动程序来驱动Web驱动程序.

I drive my Web Driver with Python and C# and with a set of different browser drivers.

例如,如果截图是使用带有Python的PhantomJS无头浏览器拍摄的,则可以获得完整的页面截图.

For example if screenshot is taken with PhantomJS headless browser with Python, I get full page shot.

在C#中,没有直接将屏幕快照作为驱动程序方法提供,因此需要一些代码(请参阅上面提到的问题和建议的C#解决方案).

In C# screenshot is not directly provided as a driver method, so a bit of code is needed (see above mentioned question and suggested C# solution).

但是,C#配方虽然可以完美地拍摄屏幕截图,但并不是我想要的.

However, C# recipe albeit working perfectly taking a screen shot, is not what I am looking for.

问题在于C#配方需要截屏,而我正在寻找的是如何截取整页.屏幕快照应该是屏幕上看到的,浏览器页面通常大于屏幕.在许多情况下,拍摄的照片应该是分页拍摄.

The problem is that C# recipe takes a screen shot, and what I am looking for is how to take a full page shot. Screen shot is expected to be what is seen on the screen, and browser pages are often larger than the screen. In many cases a shot taken shall be page shot.

此问题与在细节上引述的问题有所不同,从而使结果有所不同.我想这里欢迎使用针对不同语言的页面拍摄解决方案.

This question differ than quoted one in subtle question detail that makes difference in the result. I guess that solutions for page shoot for different languages would be welcome here.

推荐答案

当前WebDriver API中的屏幕截图定义为整页屏幕截图.通过WebDriver截屏时,无论使用哪种语言(Python,C#,Java等),都应该获得完整页面的截图.话虽如此,但有一些注意事项.

Screenshots in the current WebDriver API are defined as full-page screenshots. When you take a screenshot via WebDriver, you should be getting them of the full page, no matter what language (Python, C#, Java, etc.) you use. Having said that, there are some caveats to note.

对于IE驱动程序,如果您在64位Windows上运行并使用32位IEDriverServer.exe,则会看到屏幕截图被截断为系统显示分辨率的最大大小,并且任何溢出图像的黑色部分.这是由于Windows挂钩过程的局限性所致,这些过程用于允许IE驱动程序创建整页屏幕截图.可以在博客文章由IE驱动程序的作者提供.

For the IE driver, if you run on 64-bit Windows, and use the 32-bit IEDriverServer.exe, you'll see your screenshots truncated to the maximum size of the display resolution of the system, with any overflow as black portions of the image. This is due to the limitations of Windows hook procedures that are used to allow the IE driver to create full-page screenshots. More in-depth detail can be found in a blog post by the author of the IE driver.

Chrome驱动程序仅提供可见视口的屏幕截图.这是驱动程序的一个已知问题,已经存在了一段时间,由于潜在的

The driver for Chrome only provides screenshots of the visible view port. This is a known issue of the driver, and has been for some time, and cannot be fixed due to an underlying bug in the Chrome browser itself.

Safari驱动程序的体系结构不允许使用完整的DOM屏幕截图.由于Safari浏览器提供的扩展点的性质有限,因此不太可能会改变.

The architecture of the Safari driver doesn't allow for full-DOM screenshots. Due to the limited nature of the extension points provided by the Safari browser, it's unlikely this will change.

最后,所有有关屏幕截图的讨论仅与当前 WebDriver实现有关. W3C工作组创建一个

Finally, all of this discussion about screenshots is only relevant to current WebDriver implementations. The W3C working group creating a WebDriver spec has decided that screenshots should only be of the visible view port, so this behavior will likely change in the future, and only allow screenshots of the view port.

这篇关于使用Selenium Web Driver进行页面拍摄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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