Python Forum

Full Version: Automation WEB sel+Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi . Who can help me ?

There is a website.

I make a choice by // span [@ class = "basket-item__price-total_discount js__total-price"] of these 3 pieces

I added 3 books and went to the basket for verification.

How do I get the value 194 & nbsp and 5000 & nbsp into a variable and do the addition?
<span class="basket-item__price-total_discount js__total-price">194&nbsp;₽</span>

<span class="basket-item__price-total_discount js__total-price">5000&nbsp;₽</span>


you need to check the price of orders and the total price of the order
You store tags in a variable,then a for loop over tags and use .text collect fixed result as show under in list.
Then use sum().
span_tag =  browser.find_elements_by_xpath('//span[@class="basket-item__price-total_discount js__total-price"]')
For one tag it would be.
>>> span_tag[0].text
'194 ₽'
# Fix so only get 194
>>> span_tag[0].text.split()[0]
'194'
# Integer
>>> int(span_tag[0].text.split()[0])
194
how to check the amount of goods and add up all the goods to see if the total price is changing?
(Jul-02-2020, 09:50 AM)ABVSVL Wrote: [ -> ]how to check the amount of goods and add up all the goods to see if the total price is changing?
This is what you should try yourself by using the code hint i have given,that how it's work here Wink
So to take it step further.
span_tag =  browser.find_elements_by_xpath('//span[@class="basket-item__price-total_discount js__total-price"]')
#print(span_tag)
total = []
for tag in span_tag:
    total.append(int(tag.text.split()[0]))

print(sum(total))
Output:
5194