How I can calculate the sum of items that are stored in main Id and then sub_id in that main Id



  • 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?



  • 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
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2