How do I get the value between the start and end tag Python Selenium?

Viewed 67

I'm trying to get the value from this HTML tag automatically:

<span data-testid="TemperatureValue" class="CurrentConditions--tempValue--1RYJJ">84°</span>
The temperature value in the middle changes automatically.

Also, should I be using the XPath or the full Xpath for my find_element_by_xpath() variable?

2 Answers

Try with this

degree = driver.find_element_by_xpath("//*[@data-testid='TemperatureValue']").text

print(degree)

Use

driver.find_element_by_css_selector('span[data-testid="TemperatureValue"]').text

Store this in a variable and print it

Related