package prictce;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.sun.jna.platform.FileUtils;
public class baidu {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"); //启动驱动
WebDriver driver= new ChromeDriver(); //谷歌的驱动
driver.manage().window().maximize(); //讲窗口最大化
driver.get("http://www.baidu.com"); //打开百度
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //讲截取的图片以文件的形式返回
try {
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("d:\screenshot.png")); //使用copyFile()方法保存获取到的截图文件
} catch (IOException e) {
e.printStackTrace();
}
driver.quit();
}
}