Look at the image enter image description here

here you can see the Dom that how its showing one main div with ID and then item are there in that div. I have to calculate all the items on a page that are shown to user. These items may vary from user to user so I have to calculate it. Any solution for it?

  • To clarify, do you want the sum of all price tags, correct? Commented May 23, 2019 at 10:55

1 Answer 1


Comments explain the flow

WebElement baseCard = driver.findElement(By.id("00automation")); // Finding the base of the DOM tree where the price tag will be
List<WebElement> priceTags = baseCard.findElements(By.cssSelector(".card-price-tag")); // Find all price tags elements

Integer sumOfPriceTags = Arrays.stream(priceTags) // For each price tag
                               .reduce(0, (sum, element) // Starting from 0
                                 -> sum + extractValueFromElement(element)); // Sum the current value with the price tag value
  • I have used the above code and its showing me error for Stream that String cannot be convert into integer. Then it give option to change List <WebElement> to int[], but once I do that it start to showing other errors as well. Commented May 24, 2019 at 7:36
  • Can you share on a gist your implementation of extractValueFromElement? It has to fetch the text and remove the dollar sign before parsing the string to an int. Commented May 24, 2019 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.