Page contains several elements (9) with different String values of km. I need to catch an Integer from each element.
<li class="specItem___2u4I4" data-qa-selector="spec-mileage"><span class="specDot___2SwMP">•</span> 21.950 km</li>
My idea is the following, to find a list of elements via Xpath, getText() and put them into a list.
ArrayList<String> abcd = new ArrayList<>();
for (int i = 1; i <= amountOfElements.size(); i++) {
WebElement e = driver.findElement(By.xpath("(//li[contains(@data-qa-selector, 'spec-mileage')])['" + i + "']"));
abcd.add(e.getText());
}
System.out.println(abcd);
Unfortunately, list always return the first value nine times (by amount of elements). [• 21.950 km, • ... 21.950 km]
How can I get the list that contains values from different elements?