[Python] Python-Selenium WebDriver- Sum in the For Loop is returning Zero

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to Python and trying learn Selenium automation. I am trying get the values as a text from a table and storing them in prices variable and then iterating them to get a total after converting to integer. But the sum is returning Zero, hence assertion fails.

    prices = driver.find_elements(By.CSS_SELECTOR, "tr td:nth-child(5) p") sum = 0 for price in prices: sum = sum + int(price.text)

    print(sum) totalAmount = int(driver.find_element(By.CLASS_NAME, "totAmt").text) print(totalAmount) assert sum == totalAmount

    Any suggestion would be helpful. Thanks in advance

    As there are no syntax error, i have tried different locator to capture the elements but it didn't help.

    Continue reading...

Compartilhe esta Página