zoukankan      html  css  js  c++  java
  • 截屏操作___senium__TakeScreenshot对象

    一、代码如下

    package www.gui.v2;
    
    import java.awt.AWTException;
    import java.awt.List;
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.io.File;
    import java.io.IOException;
    import java.util.Random;
    import java.util.concurrent.TimeUnit;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;
    
    public class Capture {
    	WebDriver driver= null;
    	Actions actions= null;
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Capture gx= new Capture();
    		gx.init();
    
    	}
    	
    	private void init() {
    		// TODO Auto-generated method stub
    		// TODO Auto-generated method stub
    		// System.setProperty("webdriver.firefox.bin", "D:\Mozilla
    		// Firefox\firefox.exe");
    		System.setProperty("webdriver.firefox.bin", "D:\FireFox__37\firefox.exe");
    
    		this.driver = new FirefoxDriver();// 启动火狐浏览器
    
    		this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
    		this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
    		this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
    		this.driver.manage().window().maximize();
    		// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
    		actions = new Actions(driver);
    		
    		this.driver.get("http://localhost/Agileone/");
    		this.driver.findElement(By.id("username")).sendKeys("admin");
    		this.driver.findElement(By.id("password")).sendKeys("admin");
    		this.driver.findElement(By.id("login")).click();
    		this.driver.findElement(By.partialLinkText("需求提案")).click();
    		this.driver.findElement(By.partialLinkText("缺陷跟踪")).click();
    		
    		
    		
    		TakesScreenshot s= (TakesScreenshot)driver;
    //		byte[] b=s.getScreenshotAs(OutputType.BYTES);
    //		for(int i=0; i<b.length; i++) {
    //			System.out.println(b[i]);
    //		}
    	
    		File f= s.getScreenshotAs(OutputType.FILE);
    		try {
    			FileUtils.copyFile(f, new File("e:\123.png"));
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    	
    	
    
    }
    
  • 相关阅读:
    PHP错误:Fatal error: session_start() 解决办法
    Flash 随机生成多个显示元件的ActionScript代码
    CMD 命令行查看端口被哪个程序占用,并根据PID值,找到相应的程序,关闭掉对应服务或进程!
    DB: 20 个数据库设计最佳实践
    ActionScript 3.0 组件!
    FLASH ActionScript 3.0 sns cocial game 开发中的定时器
    PHP 获取用户真实IP
    我想成为坐在路边鼓掌的人
    Mobile + Web 并举的Social Game开发模式
    addEventListener & removeEventListener || attachEvent & detachEvent
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7667857.html
Copyright © 2011-2022 走看看