At times, we may come across elements of the same type like multiple hyperlinks, images, etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.
Sample Code
// Storing the list
List elementList =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
// Fetching the size of the list
int listSize = elementList.size();
for (int i=0; i {
// Clicking on each service provider link
serviceProviderLinks.get(i).click();
// Navigating back to the previous page that stores link to service
providers
driver.navigate().back();
}