Selenium Webdriver实现截图功能的示例
前几天在研究中自动化的时候突发奇想,想着能不能来截个图,以便之后查看,实现的方法其实也不难,毕竟seleniumwebdriver已经提供了截图额功能,TakesScreenshot接口函数(英文意思就是获取屏幕截图takes-screenshot)。
废话不多说了,直接上代码
packagecom.wch;
importjava.io.File;
importjava.io.IOException;
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Test;
importorg.openqa.selenium.OutputType;
importorg.openqa.selenium.TakesScreenshot;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
importorg.openqa.selenium.support.ui.WebDriverWait;
importcom.sun.jna.platform.FileUtils;
publicclassTestTakesScreenshot{
publicstaticvoidmain(String[]args){
System.setProperty("webdriver.firefox.bin","D:\\ProgramFiles(x86)\\MozillaFirefox\\firefox.exe");
WebDriverdriver=newFirefoxDriver();
driver.get("http://www.baidu.com");
FilesrcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);//讲截取的图片以文件的形式返回
try{
org.apache.commons.io.FileUtils.copyFile(srcFile,newFile("d:\\screenshot.png"));//使用copyFile()方法保存获取到的截图文件
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
driver.quit();
}
}
还有其他方法的话希望各位也能提供下,互相学习。
以上这篇SeleniumWebdriver实现截图功能的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下