Snapshot generated by Selenium is very large

Asked

Viewed 44 times

3

Good afternoon, everyone.

I am using Firefoxdriver in version 2.53.0 and when taking snapshot of a site is being generated an image with very large dimensions (111159x17555).

Does anyone know a way to fix this problem?

I have tried to define the browser dimension with the following code:

driver.manage().window().setSize(new Dimension(1366, 768));

And the problem persisted.

Follow the example of a snapshot that was generated. inserir a descrição da imagem aqui

Follow the code used to take the snapshot:

public static void saveScreenshot(WebDriver driver, String path) {
    File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(scrFile, new File(path));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
  • You could post the code you’re using to take the screenshoot? (e.g., all the way up to the part where you call getScreenshotAs).

  • I added the code to the post.

1 answer

0

I don’t know if it solves your case, but I could try based on my code I use on another system. I don’t really know if it solves your problem.

public BufferedImage screenshot(WebDriver driver) throws IOException {
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    BufferedImage fullImg = ImageIO.read(screenshot);
    return fullImg;
}

And I call for a method to persist

public boolean persistScreenshot(BufferedImage image, String location) {
    try {
        File file = new File(location);
        if (file.exists()) {
            file.delete();
        }
        ImageIO.write(image, "png", file);
        return true;
    } catch (Exception e) {
        return false;
    }
}

The point is, my self turns into a Bufferedimage because I don’t always need the direct persistence of it. Vla etalvez test if this would not solve the problem of him redeeming himself in the wrong way.

  • Kelvin, thanks for your help, but the problem is still there. I believe that the problem is not the code but the layout of the site, because if I take snapshot of another site the image comes out perfect.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.