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("将截屏的图片保存在桌面");
                    
        }
    
    }
  • 相关阅读:
    解决方案solution
    Marshal类
    鼠标钩子WH_MOUSE_LL和WH_MOUSE的区别
    DllImport
    打包.py文件成.exe
    C++定义全部变量注意项
    类.cpp文件不识别类.h所定义的结构体问题
    C++判断文件是否存在
    博客专栏
    软件测试基础知识
  • 原文地址:https://www.cnblogs.com/111testing/p/6135664.html
Copyright © 2011-2022 走看看