Skip to content
🎄 Christmas Advent Calendar 2025 — Unwrap daily testing tips and surprises! View Calendar

Selenium 4: Full page screenshots

22-10-2019 Roy de Kleijn

In some cases it can be useful to take a screenshot of the entire page, rather than only what is visible in the viewport. Selenium 4 provides this feature for the FireFoxDriver.

The code below demonstrates how to do that.

@Test
public void takeScreenshotTest() {
   driver.get("https://www.amazon.com");

   this.takeScreenshot(driver, new File("target/screenshot/screenshot.png"));
}

private void takeScreenshot(WebDriver driver, File destination) {
   File file = null;
   if (driver instanceof FirefoxDriver) {
      file = ((FirefoxDriver) driver).getFullPageScreenshotAs(OutputType.FILE);
   } else if (driver instanceof ChromeDriver) {
      file = ((ChromeDriver) driver).getScreenshotAs(OutputType.FILE);
   }

   try {
      FileUtils.copyFile(file, destination);
   } catch (IOException e) {
      e.printStackTrace();
   }
}

As you can see, you need to determine first which driver you are using.

Share:
Roy de Kleijn

Test Automation Expert

With over 15 years of experience in software testing and test automation, Roy helps teams improve their testing processes.

Want to learn more?

Check out our trainings and take your test automation skills to the next level.