package com.selenium.gen;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Baidu {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver=new FirefoxDriver();
driver.get("https://www.baidu.com");
//對(duì)當(dāng)前窗口截圖,并保存位置
try {
File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("d:\\screenshot.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.quit();
}
}