int lawl is over 9000
int lawl is over 9000

Reputation: 1022

ui4j - Possible to screenshot the whole page?

I would like to capture a screenshot of a website including content that you can only see if you scrolled down.

Is that possible?

EDIT: I already tried https://github.com/ui4j/ui4j/blob/master/ui4j-sample/src/main/java/com/ui4j/sample/ScreenCapture.java, but it did not capture the whole page, just the visible portion(inside my monitor's viewport).

page.show(true);
page.captureScreen(new FileOutputStream(file));

Upvotes: 1

Views: 541

Answers (1)

user452425
user452425

Reputation:

Yes, you could capture screenshot of the whole page with ui4j. Sample code:

package com.ui4j.sample;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.ui4j.api.browser.BrowserFactory;
import com.ui4j.api.browser.Page;

public class ScreenCapture {

    public static void main(String[] args) throws FileNotFoundException {
        Page page = BrowserFactory.getWebKit().navigate("https://www.google.com");
        page.show(true);
        page.captureScreen(new FileOutputStream(new File("google.png")));
    }
}

Alternative solution:

I highly recommend to use cdp4j library for full page screen capture. Its a Java library which help to automate Chrome/Chromium based browser. Here is the sample code.

Upvotes: 0

Related Questions