1

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?

2

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

driver.find_element_by_xpath("//span[contains(@class,'Trsdu')]").text
| improve this answer | |
0

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.

| improve this answer | |
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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