Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automation WEB sel+Python
#1
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
Reply
#2
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
Reply
#3
how to check the amount of goods and add up all the goods to see if the total price is changing?
Reply
#4
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Automation Engine on Python? jfha73 4 2,040 May-01-2020, 02:29 PM
Last Post: jfha73
  Python Script-To perform automation of excel values which need to be feeded into we mrinal3411 1 2,419 Jul-14-2018, 06:12 PM
Last Post: Larz60+
  [Intermediate] Python web Automation testing vardhhan 0 3,474 Feb-18-2018, 06:23 AM
Last Post: vardhhan
  Python Selenium Document Lookup and Download Automation Error - Target Machine active Guttmann 4 5,158 Apr-18-2017, 12:13 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020