//獲取元素列表public List<WebElement> ListElements(WebElement webElement, By parentBy, By childrenBy) { //定義一個list集合存儲全部的元素列表參數 List<WebElement> elements = new ArrayList<WebElement>(); int statusNum=0; By[] elementBys = {parentBy, childrenBy}; if (webElement != null) { for (int i = 0; i < elementBys.length; i++) { if (elementBys[i] != null) { statusNum=i+1; }else { continue; } } } else { System.out.println("傳輸元素爲空"); } switch (statusNum) { case 0: System.out.println("輸入數據有誤"); break; case 1: elements = webElement.findElements(parentBy); break; case 2: elements = driver.findElement(parentBy).findElements(childrenBy); break; } return elements;}