对当前窗口截图

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

//对当前窗口截图,并保存位置

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

}

}

你可能感兴趣的:(对当前窗口截图)