是否可以在 InternetExplorerDriver 中截取页面可见部分的屏幕截图?

Is it possible to take screenshot of visible part of page in InternetExplorerDriver?

我需要截取 IEDriver 中页面可见部分的屏幕截图,以与其他 drivers 保持一致。对于其他 drivers,我使用 "scroll and stitch" 方法来获取全高页面图像,但在某些情况下可能会有差异 - 例如,如果页面有粘性 header。我宁愿选择一种方式,但所有 driver 都一样,而且并非所有 driver 都提供截取整页屏幕截图的功能。

TakesScreenshot 界面的文档指出:

For WebDriver extending TakesScreenshot, this makes a best effort depending on the browser to return the following in order of preference:

  • Entire page
  • Current window
  • Visible portion of the current frame
  • The screenshot of the entire display containing the browser

我的问题是:

是否可以强制 Internet Explorer 只截取当前 window 的屏幕截图?我知道通过 API 是不可能的,但也许有一些自定义功能或内部 driver 设置可以更改?

我在 Internet Explorer 驱动程序服务器更新日志中找到了以下信息:

v2.52.0.0

  • Release to synchronize with release of Selenium project.
  • Updates to JavaScript automation atoms.
  • (on behalf of Anton Usmansky) Added ie.enableFullPageScreenshot capability to allow users to create screenshots of only the current view port. The capability defaults to true, which preserves the original behavior of resizing the browser window and taking a screenshot of the full page.

我试过了,确实有效! Java 的示例代码(适用于 IE11 - 我没有用其他版本对其进行测试):

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("ie.enableFullPageScreenshot", false);
WebDriver driver = new InternetExplorerDriver(caps);