Refactoring ByChained#findElements
The original for-each was pretty obscure,
Replacing it with the good old for.
This addresses the doubts which arose
in the review for
@@ -61,16 +61,14 @@ public WebElement findElement(SearchContext context) {
return new ArrayList<>();
}
- List<WebElement> elems = null;
- for (By by : bys) {
+ List<WebElement> elems = bys[0].findElements(context);
+ for (int i = 1; i < bys.length; i++) {
+ if (elems.isEmpty()) {
+ break; // if any one of the bys finds no elements, then return no elements
+ }
List<WebElement> newElems = new ArrayList<>();
-
- if (elems == null) {
- newElems.addAll(by.findElements(context));
- } else {
for (WebElement elem : elems) {
- newElems.addAll(elem.findElements(by));
- }
+ newElems.addAll(elem.findElements(bys[i]));
}
elems = newElems;
}
