Appnium封装各种查找元素的方法如下显示:
//封装查找元素方法
public class AppniumFindElementUtil {
private static WebElement webElement;
private static List<WebElement> webElements;
public static WebElement findElement(AndroidDriver<WebElement> driver,
String tag, String value) {
switch (tag) {
case "ByText":
webElement = driver.findElementByAndroidUIAutomator(value);
break;
case "ById":
webElement = driver.findElement(By.id(value));
break;
case "ByElementsByXPath":
webElements = driver.findElementsByXPath(value);
break;
case "ByElementByXPath":
webElement = driver.findElementByXPath(value);
break;
case "ByClassName":
webElement = driver.findElementByClassName(value);
break;
case "ByName":
webElement = driver.findElementByName(value);
break;
case "ByLinkText":
webElement = driver.findElementByLinkText(value);
break;
}
return webElement;
}
}
//判断元素是否存在
private static boolean flag;
public static boolean isElementExist(AndroidDriver<WebElement> driver,
String tag, String value) {
flag=true;
try {
AppniumFindElementUtil.findElement(driver, tag, value);
return flag;
} catch (Exception e) {
flag=false;
}
return flag;
}
appnium保存截图