刀剑神域第二季15集,热血无赖白屏未响应,峰回路转造句
前几天在研究中自动化的时候突发奇想,想着能不能来截个图,以便之后查看,实现的方法其实也不难,毕竟selenium webdriver已经提供了截图额功能,takesscreenshot接口函数(英文意思就是获取屏幕截图takes-screenshot)。
废话不多说了,直接上代码
package com.wch; import java.io.file; import java.io.ioexception; import org.junit.after; import org.junit.before; import org.junit.test; import org.openqa.selenium.outputtype; import org.openqa.selenium.takesscreenshot; import org.openqa.selenium.webdriver; import org.openqa.selenium.firefox.firefoxdriver; import org.openqa.selenium.support.ui.webdriverwait; import com.sun.jna.platform.fileutils; public class testtakesscreenshot { public static void main(string[] args) { system.setproperty("webdriver.firefox.bin", "d:\\program files (x86)\\mozilla firefox\\firefox.exe"); webdriver driver = new firefoxdriver(); driver.get("http://www.baidu.com"); file srcfile = ((takesscreenshot)driver).getscreenshotas(outputtype.file); //讲截取的图片以文件的形式返回 try { org.apache.commons.io.fileutils.copyfile(srcfile, new file("d:\\screenshot.png")); //使用copyfile()方法保存获取到的截图文件 } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } driver.quit(); } }
还有其他方法的话希望各位也能提供下,互相学习。
以上这篇selenium webdriver实现截图功能的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论