In many cases, when you want to apply some operation to a certain range List, you can usesubList() :
for (WebElement element : elements.subList(3, 7)) {
// do stuff
}
This is also great for removing some range:
myList.subList(4, 14).clear();
Please note that subListonly exists on List, so this will not work on objects Setor other non-List Collection.
source
share