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("将截屏的图片保存在桌面");
                    
        }
    
    }
  • 相关阅读:
    无旋转Treap简介
    bzoj 4318 OSU!
    bzoj 1419 Red is good
    bzoj 4008 亚瑟王
    bzoj 1014 火星人prefix
    更多的莫队
    bzoj 3489 A simple rmq problem
    洛谷 2056 采花
    NOIP 2017 游(划水)记
    UVa 11997 K Smallest Sums
  • 原文地址:https://www.cnblogs.com/111testing/p/6135664.html
Copyright © 2011-2022 走看看