美文网首页
对当前窗口截图

对当前窗口截图

作者: 红木杉2018 | 来源:发表于2017-03-21 17:13 被阅读0次

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

    }

    }

    相关文章

      网友评论

          本文标题:对当前窗口截图

          本文链接:https://www.haomeiwen.com/subject/fdpgnttx.html