2

I would like to execute Firefox's screenshot --fullpage command from inside a Selenium java script.

The command is documented in Take a full page screenshot with Firefox

Is it possible?

Alex R
  • 11,364
  • 15
  • 100
  • 180

1 Answers1

-2

You can just take a screenshot from within your Java code. From this answer: https://stackoverflow.com/a/3423347/8020699

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

This guy suggests using a library called aShot to take full page screenshots. Here's the link to the aShot jar. Here's the code he gives:

import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

public class FullPageScreenshot {
    public static void main(String args[]) throws Exception{
        //Modify the path of the GeckoDriver in the below step based on your local system path
        System.setProperty("webdriver.gecko.driver","D://Selenium Environment//Drivers//geckodriver.exe");
        // Instantiation of driver object. To launch Firefox browser
        WebDriver driver = new FirefoxDriver();
        // To oepn URL "http://softwaretestingmaterial.com"
        driver.get("http://www.softwaretestingmaterial.com");
        Thread.sleep(2000);
        Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
        ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
    }
}
  • But `Not_in_(granted it's in python)` its `Java`. Thanks – undetected Selenium Jul 29 '17 at 10:08
  • aShot is a bit unreliable (gets stuck on some pages) and not as nice (unwanted repetition of 'fixed' elements) when compared to the built-in `screenshot --fullpage` command in the Firefox console – Alex R Aug 25 '17 at 23:58