对当前窗口截图

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

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,347评论 19 139
  • package wrapFunc; import java.io.File; import java.io.IOE...
    yoyoswj阅读 4,095评论 0 0
  • 一. Java基础部分.................................................
    wy_sure阅读 9,239评论 0 11
  • 一、 1、请用Java写一个冒泡排序方法 【参考答案】 public static void Bubble(int...
    独云阅读 5,244评论 0 6
  • 二胎时代来了,大家都忙着生老二。我家也不落后,再过五六天,我们就满月了。 可是关于老大的问题很“严重”。说严重,其...
    像夏花一样绚烂阅读 1,384评论 0 1