Cannot get text of element with Selenium

kyletoffan292

I have the DOM element below:

<span class="styles__Content-rlm06o-1 ixoRjG">20.00000000</span>

that I am trying to get the 20.00000000 value from with:

text = driver.find_elements_by_xpath("//*[@class='styles__Content-rlm06o-1 ixoRjG']")[0].text
...
number = float(text)

But Python returns back could not convert string to float: '' meaning that the 20.00000000 is not being recognized as text. This code has worked on other websites, so maybe this is a website specific thing? Or is there something I'm overlooking?

vitaliis

You can try to get the text of the first element with this xpath:

el_text = driver.find_element_by_xpath("//span[contains(@class, 'styles__Content-rlm06o-1 ixoRjG')][1]").text

Also, you can use css selectors with way:

el_text = driver.find_element_by_css_selector(".styles__Content-rlm06o-1.ixoRjG:nth-of-type(1)").text

If text is still empty, make sure you are waiting for the element to become visible and that this element is not inside iframe.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Selenium webdriver cannot get an element

Selenium how to get text element

How to get text of an element in Selenium?

Python: Selenium cannot click XPath text element

Selenium c# cannot locate element with text

Cannot get dynamical element with python selenium

How to select element with selenium in python and get the text?

Python selenium: Get dynamic update of text of an element

Selenium webdriver - relative xpath, get element with text

Selenium JS how to get text of an element

Python selenium get text from href element

Unable to get text from input element in selenium

Unable to get element text using Selenium with Chrome

How to get text of td element using selenium?

Selenium can't get the text from element

python selenium get text from element

How to get text element in html head by selenium?

Best way to get text of this element in selenium

How to get text from an element with selenium

Python, Selenium: How to get text next to element

Get text from html element using selenium

Cannot get the text of a child element in javascript

Selenium - How to get the text from an element but retaining child element source

Python 3.10: I cannot extract text from an element with Selenium 4.8.0

Selenium cannot locate an element

Python Selenium cannot get anything when using .text method

Get the class name of the immediate parent of element with inner text using selenium

Python and how to get text from Selenium element WebElement object?

Get text of htlm inline element class with python selenium chromedriver