Here's an advance on @kwishna's answer which stitches the screenshots together into a single image:
public void takeFullPageScreenShot(WebDriver driver) throws IOException {
JavascriptExecutor jsExec = (JavascriptExecutor) driver;
jsExec.executeScript("window.scrollTo(0, 0);");
Long innerHeight = (Long) jsExec.executeScript("return window.innerHeight;");
Long scroll = innerHeight;
Long scrollHeight = (Long) jsExec.executeScript("return document.body.scrollHeight;");
scrollHeight = scrollHeight + scroll;
List<byte[]> images = new ArrayList<>();
do {
byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
images.add(screenshot);
jsExec.executeScript("window.scrollTo(0, "+innerHeight+");");
innerHeight = innerHeight + scroll;
} while (scrollHeight >= innerHeight);
BufferedImage result = null;
Graphics g = null;
int x = 0, y = 0;
for(byte[] image : images){
InputStream is = new ByteArrayInputStream(image);
BufferedImage bi = ImageIO.read(is);
if (result == null) {
// Lazy init so we can infer height and width
result = new BufferedImage(
bi.getWidth(), bi.getHeight() * images.size(),
BufferedImage.TYPE_INT_RGB);
g = result.getGraphics();
}
g.drawImage(bi, x, y, null);
y += bi.getHeight();
}
ImageIO.write(result,"png",new File("result.png"));
}