Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium text not working

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.

like image 255
dan-klasson Avatar asked Dec 22 '25 01:12

dan-klasson


1 Answers

get_attribute("textContent") or get_attribute("innerText") are the attributes you are looking for.

like image 60
Guy Avatar answered Dec 23 '25 14:12

Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!