0

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? – João Farias May 23 at 10:55
4

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. – Muhammad Atif Muneeb Alrai May 24 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. – João Farias May 24 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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