the html code

In the code above, how would I get the span class value (238.67) to show up? What would I exactly use?

3 Answers 3


enter code hereI assume you have only one span tag.

This xpath will locate the element. //span[contains(@class,'Trsdu')]

Below code will return you the 238.67 value


I may be missing context here and I am not super sure what do you mean by to show up but to get that value I would use the data-reactid as selector and just get the innerhtml text on that element.


If the span's class value does not include multiple keywords then we can easily extract the element's text using locator "//span[@class ='Trsdu']" with '.text' property.

Please refer below code:

print("Text Returned", driver.find_element_by_xpath("//span[@class='Trsdu']").text)

However, the span element provided in the screenshot -> has multiple keywords in its class value. So for this scenario, software testing services use '.contains' method to locate the element and the same .text property can be used to extract the element's text

Please refer below code:

print("Text extracted using contains", driver.find_element_by_xpath("//span[contains(@class,'Trsdu')]").text)

For the '.contains' approach, always try to use a unique keyword from the provided class value to avoid returning multiple elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.