Python Selenium - text_to_be_present_in_element with numbers

Viewed 203

I'm trying to wait for an element to match a specific number with Selenium in Python. It basically can assume every value between 0 and 100. Matching words is functional but matching numbers is a bit problematic.

The code:

WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.ID, 'price'),"1"))

matches the value 1 but also 10,11,21 and every number that contains "1". Is there a more pythonic and efficient way than this?

while price != '1':
    price = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'price'))).text

Thanks. Df.

1 Answers

You can cast your text to an integer value like this:

PRICE = int(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'price'))).text)

Now you can check with a number instead of strings

Related