Your ultimate guide

Automation_Take Screen Shot

getScreenshotAs():

    By using this method we can take Screenshots of the current Web Page.

Syntax:
    TakesScreenshot tshot = (TakesScreenshot)driver;
    File src = tshot.getScreenshotAs(OutputType.FILE);
    File dest = new File("destination path\\filename.jpg");
    FileHandler.copy(src, dest);

Syntax 2:
    File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    File dest = new File("destination path\\filename.jpg");
    FileHandler.copy(src, dest);



Example:
public class TScreenshot
{
    public static void main(String[] args) throws IOException
    {
        System.setProperty("webdriver.edge.driver",".//edgedriver.exe");
        WebDriver driver = new EdgeDriver();
        String Url = "https://testingcolleges.blogspot.com";
        driver.get(Url);

        TakesScreenshot screenshot = (TakesScreenshot)driver;
        File source = screenshot.getScreenshotAs(OutputType.FILE);
        File destination = new File("E:\\123.jpg");
        FileHandler.copy(source, destination);
    }
}


No comments:

Post a Comment