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"));