I have a list of li elements wrapped in sub-menu class of HTML, before clicking on any of the li element I wanted to cross check all li elements are present with getText()
and length
but not sure how to go with length
as I don't see any suggestion to go for length.
WebElement menuList = driver.findElement(By.id("menu-item-33"));
menuList.click();
List<WebElement>elems = driver.findElements(By.className("sub-menu"));
for (WebElement ddlList : elems)
{
System.out.println(ddlList.getText());
//Something like ddlList.length(); but not able to work upon it.
}
}
ddlList
is an individual element . . . if you just want to know how many you had, you want the length ofelems
. .