selenium案例一

上一篇 / 下一篇  2016-12-21 11:52:49 / 个人分类:Selenium

package com.quark.util;
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class UploadFile {
 public static void uploadAndClose(WebDriver brws,String framId,String num) throws InterruptedException, IOException{
  //上传文件并且返回到主页面
  String legendB = ".//*[@id='" + framId + "_legend']/div/button";
  String selectB = ".//*[@id='" + framId + "_SelectButton']/lable";
  String frameStr = framId + "_iframe";
  String xpathStr = "html/body/div[" + num + "]/div[1]/button";
  brws.findElement(By.xpath(legendB)).click();
  brws.findElement(By.xpath(selectB)).click();
  Thread.sleep(500);
  WebElement newFrameElem = brws.findElement(By.id(frameStr));
  brws.switchTo().frame(newFrameElem);
  brws.findElement(By.id("pickfiles")).click();
  Thread.sleep(500);
  String picPath = new File("res/test.jpg").getAbsolutePath();
  Runtime.getRuntime().exec("res/upload.exe " + picPath);
  Thread.sleep(4000);
  brws.switchTo().defaultContent();
  brws.findElement(By.xpath(xpathStr)).click();
  Thread.sleep(1000);
 }
}

TAG:

 

评分:0

我来说两句

Open Toolbar