JAVA

要拍攝並儲存螢幕截圖的程式碼:

public class Sample 
{
    public static void main (String[] args) 
    {
        *//Initialize Browser*
        System.setProperty("webdriver.gecko.driver", "**E:\\path\\to\\geckodriver.exe**");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();        
        driver.get("https://www.google.com/");
        
        //Take Screesnshot
        File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        try {
            //Save Screenshot in destination file
            FileUtils.copyFile(src, new File("D:\\screenshot.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

拍攝截圖:

File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

商店從源到目的地的螢幕截圖:

FileUtils.copyFile(src, new File("D:\\screenshot.png"));