1

I am trying to automate some test cases, for on test case I need a particular temperature value in integer. However, the value coming from

driver.find_element_by_id("temperature").text

is a string like 12°C. I want to extract 12 as an integer. See the screenshot for better understanding.enter image description here

1
  • <your_code>.text Commented Aug 2, 2021 at 15:14

2 Answers 2

1

see when you do,

driver.find_element_by_id("temperature").text

it is gonna return a string.

so it will look like this "12°C"

see below, we will split using '°', this and we will have an array, and we would be interesting in first element of that. Below is the full demonstration.

s = "12°C"
a = s.split('°')

print(type(s))
b = int(a[0])
print(b)
Sign up to request clarification or add additional context in comments.

Comments

0

You can extract number from a string with this:

import re

print (re.findall('\d+', str1 ))

Where str1 is a string you extracting from a web element

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.