/** * 上传照片 */
public void uploadImg(){
ListimgInfoList = new ArrayList();
//上传多张不同路径地址照片
imgInfoList.add(new String[] {"1","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传前景照" });
imgInfoList.add(new String[] {"2","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传发动机全景照" });
imgInfoList.add(new String[] {"3","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传驾驶室照" });
imgInfoList.add(new String[] {"4","C:\\Documents and Settings\\Administrator\\桌面\\中福永和菜单.jpg","上传左前侧面照" });
imgInfoList.add(new String[] {"5","C:\\Documents and Settings\\Administrator\\桌面\\中福永和菜单.jpg","上传右前侧面照" });
imgInfoList.add(new String[] {"6","C:\\Documents and Settings\\Administrator\\桌面\\中福永和菜单.jpg","上传左后侧面照" });
imgInfoList.add(new String[] {"7","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传右后侧面照" });
imgInfoList.add(new String[] {"8","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传液压泵照片" });
imgInfoList.add(new String[] {"9","C:\\Documents and Settings\\Administrator\\桌面\\psbCAD85IHE.jpg","上传其他照片" });
String[] imgInfo = null;
// 查找输入框元素
ListwebeleList = driver.findElements(By.xpath("//input[@name='importFile']"));
// 上传图片
for (int l = 0; l < imgInfoList.size(); l++) {
imgInfo = imgInfoList.get(l);
// getAttribute获取href / src 属性(相对路径)值
String imgId = driver.findElement(By.id("img" + imgInfo[0])).getAttribute("src");
// 输出照片存放地址
System.out.println("imgId:" + imgId);
// 判断照片是否已上传
if ("".equals(imgId)) {
System.out.println("《开始上传》:" + imgInfo[2]);
//for循环处理上传多张图片
for (int j = 0; webeleList != null && j < webeleList.size(); j++) {
String onchange = webeleList.get(j).getAttribute("onchange");
// System.out.println("onchange:"+onchange);
if (onchange.equals("uploadImg(this," + imgInfo[0] + ")")) {
webeleList.get(j).sendKeys(imgInfo[1]);
break;
}else{
System.out.println("已上传" );
}
}
// 关闭图片上传成功提示 弹框处理 false取消或者关闭提示框,ture点击'确定'
boolean alter = FindAlert.alert(driver, true);
// 关闭图片查看提示 弹框处理 false取消或者关闭提示框,ture点击'确定'
boolean alter1 = FindAlert.alert(driver, true);
System.out.println("【完成上传】:" + imgInfo[2]);
}
}
}