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("将截屏的图片保存在桌面");
                    
        }
    
    }
  • 相关阅读:
    Git使用教程与基本原理和Sourcetree基本使用探微
    微博开发笔记上(未完待续)
    Swift入门
    刀哥之指纹识别biometrics
    iOS面试关于http知识点basic-01-http
    SDWebImageInfo
    runloop
    NSOperation类
    java多线程
    java集合类(二)
  • 原文地址:https://www.cnblogs.com/111testing/p/6135664.html
Copyright © 2011-2022 走看看