简体   繁体   中英

Selenium - Firefox webdriver will only take partial screenshot

From what I've read the following code:

    File s = ((TakesScreenshot)driver_).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(s,new File("C:\\scr.png"));
    } catch (IOException exception) {
        exception.printStackTrace();
    }

Should take a full page screenshot. But in my case it will only take the screenshot of whatever is currently visible in the browser window. Is this the expected behaviour or did something go wrong in the code?

Yes it is expected behavior from firefox. If you want to take full page screenshot you can use something like this to zoom out the whole contents to visible area

executor = (JavascriptExecutor)driver.getDriver();
executor.executeScript(
         "document.body.style.zoom=
            (top.window.screen.height-70)/
            Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");
File scrFile = ((TakesScreenshot)driver.getDriver()).getScreenshotAs(OutputType.FILE);

It will try to bring all the content to visible area, although you can still miss some content from the very bottom area.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM