I have this span tag:
<span class="pricefield" data-usd="11000">$11,000</span>
And I want to get the text for it ($11,000). Naturally I should be using text like so:
# empty
print self.selenium.find_element_by_css_selector(".pricefield").text
But it prints nothing.
This doesn't work either:
# None
print self.selenium.find_element_by_css_selector(".pricefield").get_attribute("text")
# None
print self.selenium.find_element_by_css_selector(".pricefield").get_attribute("value")
However, I can get the elements attributes just fine:
# 11000
print self.selenium.find_element_by_css_selector(".pricefield").get_attribute("data-usd")
Why doesn't this work? Did something change in Selenium? I am using 2.52.0.
get_attribute("textContent") or get_attribute("innerText") are the attributes you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With