Search code examples
seleniumwebdriverselenium-iedriver

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


I need to take screenshot of only visible part of the page in IEDriver to have consistency with other drivers. With other drivers I use "scroll and stitch" method to get full height page image, but in some cases there can be differences - for example if page has sticky header. I would rather go one way or another, but same for all drivers, and not all drivers provide ability to take full page screenshot.

Docs for TakesScreenshot interface states this:

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

My question is:

Is it possible to force Internet Explorer to take screenshot only of current window? I know it is not possible via API but maybe there is some custom capability or internal driver setting which can be changed?


Solution

  • I have found this information in Internet Explorer Driver Server changelog:

    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.

    I tried it and it actually works! Example code for Java (works with with IE11 - I didn't test it with other versions):

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