3

I have a Selenium-Java based Automation testing framework and I need to capture the entire screen when linking screenshots to reports. The page is long and wide and has both horizontal and vertical scroll bars. Is there any utility or workaround to address that?

Tried TakesScreenshot, AShot and Shutterbug utilities but none of them are capturing the entire screen.

  • [This question](https://stackoverflow.com/questions/56163647/selenium-java-how-to-get-get-total-page-length) deals with vertical scrolling. Might help. – Mate Mrše May 23 '19 at 10:17
  • I tried getting page height using JSE as suggested in the link and passing it to AShot, but it didnt work. I'm still getting screenshots for the part of the page thats visible at the default scroll position. – Arjun Tandon May 27 '19 at 03:53

1 Answers1

1

In Selenium 4, FirefoxDriver provides a getFullPageScreenshotAs method that handles vertical and horizontal scrolling, as well as fixed elements (e.g. navbars).

System.setProperty("webdriver.gecko.driver", "path/to/geckodriver");
final FirefoxOptions options = new FirefoxOptions();
// set options...
final FirefoxDriver driver = new FirefoxDriver(options);
driver.get("https://stackoverflow.com/");
File fullScreenshotFile = driver.getFullPageScreenshotAs(OutputType.FILE);
// File will be deleted once the JVM exits, so you should copy it
Unmitigated
  • 76,500
  • 11
  • 62
  • 80