我需要獲取列表中的所有項目,但我的腳本只顯示第一個項目。請參閱for循環中的verifyDisplay斷言,我想在其中顯示列表中的所有項目。謝謝您的幫助。如何獲取列表中的所有項目
我的腳本:
List<WebElement> groups = driver.findElements(By
.xpath(".//*[@id='competitiveCategoryTemp']/option"));
verifyDisplay("'" + competitive_categories_id_with_space + "'" + "===> The newly added Competitive Category is listed",
By.xpath(".//*[@id='competitiveCategoryTemp']/option"));
boolean sortedGroups = false;
for (int i = 0; i < groups.size() - 1; i++) {
verifyDisplay("'" + groups.get(i).getText() + "'" + "\n"+
"Other Competitive Categories are available and names are SORTED",
By.xpath(".//*[@id='competitiveCategoryTemp']/option"));
if (groups.get(i).getText()
.compareToIgnoreCase(groups.get(i + 1).getText()) > 0) {
sortedGroups = true;
break;
}
sortedGroups = true;
}
if (sortedGroups) {
System.out.println("The Competitive Category names are SORTED");
} else
System.out.println("The Competitive Category names are UN-SORTED");
}
你有沒有設置斷點,並使用調試器? – Ascalonian 2015-01-20 20:19:06