'How to Capture Full page screenshot of using selenium WebDriver

I have created a Selenium Full page screenshot test for Responsive tests using selenium. But if I am going to run against the SharePoint Site then it's not taking a full-page screenshot but If I'll give any particular public site to capture the screenshots.

Here is the code snippet:

public class resTest {
@Test(groups = {"Test1"})
    public void ResTest() throws InterruptedException, IOException {
        System.setProperty("webdriver.gecko.driver", "C:\\browserdriver\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get(getUrl());
        
        driver.manage().window().maximize();

        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));

        //Enter email ID
        WebElement enterEmail = wait.until(ExpectedConditions.elementToBeClickable(By.name("loginfmt")));
        enterEmail.sendKeys(getUsername());

        WebElement clickNext = wait.until(ExpectedConditions.elementToBeClickable(By.className("win-button")));
        clickNext.click();

        //Enter Password
        WebElement SubmitPass = wait.until(ExpectedConditions.elementToBeClickable(By.name("passwd")));
        SubmitPass.sendKeys(getPassword());

        //Click on Sign In button
        WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='Sign in']")));
        element.click();

        WebElement afterNext = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='No']")));
        afterNext.click();

        Thread.sleep(9000);

        File src = ((FirefoxDriver)driver).getFullPageScreenshotAs(OutputType.FILE);
        FileHandler.copy(src, new File(System.getProperty("user.dir")+"/Res2/screen.png"));

    }
}


Solution 1:[1]

On a headless browser I use the following to get a screen of the full page

full_width  = driver.execute_script('return document.body.parentNode.scrollWidth')
full_height = driver.execute_script('return document.body.parentNode.scrollHeight')
driver.set_window_size(full_width, full_height)
driver.save_screenshot(path)

Try if you can use it also in your case

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sound wave