• Webdriver中实现区域截图的方式以及如何截取frame中的图片


    import java.awt.Rectangle;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.Point;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    public class ScreenShot {
        public  void screenShotForElement(WebDriver driver,WebElement element, String path,int x,int y) throws InterruptedException {
            //截取整个页面的图片
            File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
            try {
                //获取元素在所处frame中位置对象
                Point p = element.getLocation();
                //获取元素的宽与高
                int width = element.getSize().getWidth();
                int height = element.getSize().getHeight();
                //矩形图像对象
                Rectangle rect = new Rectangle(width, height);
                BufferedImage img = ImageIO.read(scrFile);
                //x、y表示加上当前frame的左边距,上边距
                BufferedImage dest = img.getSubimage(p.getX()+x, p.getY()+y,rect.width, rect.height);
                ImageIO.write(dest, "png", scrFile);
                FileUtils.copyFile(scrFile, new File(path));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

  • 相关阅读:
    jQuery 基本选择器
    JavaScriptif while for switch流程控制 JS函数 内置对象
    JavaScrip基本语法
    数据库 存储引擎 表的操作 数值类型 时间类型 字符串类型 枚举集合 约束
    数据库基础知识 管理员 用户登录授权的操作
    粘包的产生原理 以及如何解决粘包问题
    socket TCP DPT 网络编程
    2018年年终总结
    Android技术分享
    No accelerator found
  • 原文地址:https://www.cnblogs.com/zw520ly/p/5875546.html
Copyright © 2020-2023  润新知