//获取元素列表
public List<WebElement> ListElements(By parentBy, By childrenBy, By grandchildrenBy) {
//定义一个list集合存储所有的元素列表参数
List<WebElement> webElements = new ArrayList<WebElement>();
int statusNum=0;
By[] elements = {parentBy, childrenBy, grandchildrenBy};
for (int i = 0; i < elements.length; i++) {
if (!elements[i].equals(null)) {
statusNum=i+1;
}else {
continue;
}
}
switch (statusNum) {
case 0:
System.out.println("输入数据有误");
break;
case 1:
webElements = driver.findElements(parentBy);
break;
case 2:
webElements = driver.findElement(parentBy).findElements(childrenBy);
break;
case 3:
webElements = driver.findElement(parentBy).findElement(childrenBy).findElements(grandchildrenBy);
break;
}
return webElements;
}
原文:https://www.cnblogs.com/xxsl/p/10096904.html