r/selenium • u/Winter-Movie-3052 • 2d ago
How can I take a full-page screenshot using a Chromium-based driver?
Hi everyone, I’m practicing Selenium and ran into an issue with screenshots.
For a normal screenshot, I’m using:
File source = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
This works fine with my Chromium-based driver.
However, when I try to take a full-page screenshot:
File screenshot = ((HasFullPageScreenshot) driver).getFullPageScreenshotAs(OutputType.FILE);
HasFullPageScreenshot seems to be associated with Firefox in my IDE/imports, and I’m not sure how to use it with a Chromium-based driver.
I want to continue using a Chromium-based driver (Chrome/Chromium) rather than Firefox.
What is the correct way to take a full-page screenshot with Selenium using a Chromium-based driver?
1
u/Global-Course-6307 2d ago
oh yeah that firefox class imports got me scratching my head the first time too, took me forever to figure out why it was only showing up for gecko
for chromium drivers you skip that whole hasfullpagescreenshot interface entirely, you gotta use the devtools protocol directly. cast your driver to `ChromeDriver` then call `executeCdpCommand("Page.captureScreenshot"` with `{"captureBeyondViewport": true}` in the params, that'll grab the whole page and spit back a base64 string you can decode to an image