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.

1
  • 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. Commented Aug 14, 2020 at 13:58

2 Answers 2

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()!='']")))
Sign up to request clarification or add additional context in comments.

Comments

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.

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.