0

A dynamically generated website has such an element:

<b class="2020-is-terrible"></b>

After some time it fills the b element with a random number like this:

<b class="2020-is-terrible">42</b>

I want to wait for that number to be generated and for now I've come up a code that waits for a specific number:

WebDriverWait(driver, 10).until(expected_conditions.text_to_be_present_in_element((By.CLASS_NAME, "2020-is-terrible"), "42"))

But I want to continue if any value appears in the b element (not just 42). The value will always be a number so I just need to check if the text not empty.

List of expected_conditions classes so you don't need to google.

user1
  • 945
  • 2
  • 13
  • 37
  • 1
    I'm not a Python guy, so I do not know the correct syntax, but did you tried to check if the fetched text is not empty and is numeric? You can do that in `until` part. – Jonah Aug 14 '20 at 13:58

2 Answers2

1

With xpath you can also use the and operator by combine class name and text!='', like this:

//b[@class='2020-is-terrible' and text()!='']

Try this:

WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//b[@class='2020-is-terrible' and text()!='']")))
frianH
  • 7,295
  • 6
  • 20
  • 45
0

Here is a solution that worked for me:

WebDriverWait(driver, 10).until(lambda wd: wd.find_element_by_class_name("threat-score").text != "")

My mistake was assuming that I have to use one of the expected_conditions classes in until.

Thanks to Jonah for the hint and Dmytro Serdiuk for an example.

user1
  • 945
  • 2
  • 13
  • 37