Windows 7 32 上 selenium 2+sikuli解決swfupload類型上傳插件

  1. 安裝sikuli,安裝完成以後,安裝目錄在C:\Program Files,將 安裝文件複製到c盤下css

  2. 配置環境變量java

  3. 安裝eclipse,將selenium的java版本的jar包,添加到你是使用的工程裏面python

  4. 在sikuli-ide下面有一個sikuli_script.jar,將它添加到你使用的工程裏面apache

  5. 在程序裏面添加上用戶圖片保存的目錄,這一點很重要,不然會提示圖片找不到app

  6. 具體程序以下eclipse


  7. package com.client.pmj;
    import java.util.concurrent.TimeUnit;
    
    import org.apache.commons.jxpath.ri.compiler.Path;
    import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
    import org.openqa.selenium.*;
    import org.openqa.selenium.WebDriver.*;
    import org.openqa.selenium.firefox.*;
    import org.openqa.selenium.lift.find.ImageFinder;
    import org.python.antlr.PythonParser.if_stmt_return;
    import org.python.modules.thread.thread;
    import org.sikuli.script.*;
    
    public class Client {
    
    	public static void main(String[] args) {
    		System.out.println("helloworld");
    
    		System.out.println("hello world!");
    		WebDriver driver = new FirefoxDriver();
    		String base_url = "http://www.cxxxxn.com/";
    		driver.get(base_url+"sign_in");
    		driver.manage().window().maximize();
    		driver.findElement(By.id("mail")).clear();
    		driver.findElement(By.id("mail")).sendKeys("account");
    		driver.findElement(By.id("pwd")).clear();
    		driver.findElement(By.id("pwd")).sendKeys("password");
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		driver.findElement(By.cssSelector("button.btn-grey.btn-regular")).click();
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}		
    		WebElement step_1 = driver.findElement(By.id("submenu")).findElement(By.tagName("a"));
    		step_1.click();
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		//測試flash上傳插件模塊
    		ImageLocator  p = new ImageLocator();
    		String[] path = p.getImagePath();
    		ImageLocator.addImagePath("E:\\atuo");//添加用戶保存圖片的目錄
    		path = p.getImagePath();
    		System.out.println(path.length);
    		Screen s = new Screen();
    		try {
    			s.click("app.png");
    		} catch (FindFailed e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		try {
    			Thread.sleep(6000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		driver.quit();
    		
    		
    	}
    
    }
相關文章
相關標籤/搜索