zoukankan      html  css  js  c++  java
  • selenium webdriver 截屏操作

    有时候我们需要进行截屏操作,特别是遇到一些比较重要的页面信息(出现错误)或者出现不同需要进行对比时,

    我们就需要对正在处理的页面进行截屏!

    未经作者允许,禁止转载!

    package test_wait20161205;
    
    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.chrome.ChromeDriver;
    
    public class screen_shot20161205 {
    
        public static void main(String[] args) throws InterruptedException, IOException {
            // TODO Auto-generated method stub
            System.setProperty("webdriver.chorme.driver", "C:\Training\Automation\Software\drivers\chromedriver_win32\chromedriver.exe");和上面一行是连着的
            WebDriver driver=new ChromeDriver();
            driver.get("https://www.hao123.com/");
            Thread.sleep(1000);
            
            File screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);-------------------------截屏操作        
            FileUtils.copyFile(screenshot, new File("C:\Users\chenjia\Desktop\screenshots1.jpg"));----------保存图片
            
            System.out.println("将截屏的图片保存在桌面");
                    
        }
    
    }
  • 相关阅读:
    常用正则
    使用html2canvas 图片 清晰性高 兼容好
    倒计时调用
    多线程实现等待屏(欢迎屏)的实现
    代码生成机器人被360软件管家收录
    代码生成器1.0正式发布
    代码生成器
    代码生成器 - 第一版最终版
    ICSharpCode.TextEditor使用经验
    代码生成器
  • 原文地址:https://www.cnblogs.com/111testing/p/6135664.html
Copyright © 2011-2022 走看看