Reputation: 243
So, essentially I want to get the text from the site and print it onto console. This is the HTML snippet:
<div class="inc-vat">
<p class="price">
<span class="smaller currency-symbol">£</span>
1,500.00
<span class="vat-text"> inc. vat</span>
</p>
</div>
Here is an image of the DOM properties:
How would I go abouts retrieving the '1,500.00'? I have tried to use self.browser.find_element_by_xpath('//*[@id="main-content"]/div/div[3]/div[1]/div[1]/text()')
but that throws an error which says The result of the xpath expression is: [object Text]. It should be an element. I have also used other methods like .text
but they either only print the '£' symbol, print a blank or throw the same error.
Upvotes: 1
Views: 337
Reputation: 29372
You can use below css :
p.price
sample code :-
elem = driver.find_element_by_css_selector("p.price").text.split(' ')[1]
print(elem)
Upvotes: 1