分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

关于在selenium 中 webdriver 截图操作

发布时间:2023-09-06 01:12责任编辑:熊小新关键词:selenium

package prictce;

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.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver; ?
import org.openqa.selenium.support.ui.WebDriverWait;
import com.sun.jna.platform.FileUtils;

public class baidu {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");  //启动驱动
WebDriver driver= new ChromeDriver(); ?//谷歌的驱动
driver.manage().window().maximize(); ???//讲窗口最大化
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) { ?
????????
???????e.printStackTrace(); ?
???} ?
???driver.quit(); ?
} ?
}

关于在selenium 中 webdriver 截图操作

原文地址:http://www.cnblogs.com/yushengaqingzhijiao/p/7560290.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved