Selenium截屏操作代码
由于一点小需求,需要用到截屏。
个人记录,代码如下:
public class screen {
public void screenFun() {
//获取当前时间时间戳
long timestamp = new Date().getTime();
String title = driver.getTitle();
// TODO Auto-generated constructor stub
try{
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//将文件保存到E:\\selenium screen 并用取得的时间戳作文件名
FileUtils.copyFile(srcFile, new File("E:\\selenium screen\\"+title+timestamp+".png"));
} catch (Exception e)
{
e.printStackTrace();
}
}
}

浙公网安备 33010602011771号