0

I want to load my driver until the text of an element become numbers:

here is the element:

<span id="viewed">-<span> or <span id="viewed"><span>

it will become :

<span id="viewed">12345<span>

any solution?

1 Answer 1

1

This is untested:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

ints = "012345679"

def custom_ec(driver):
    ''' Custom expected condition function to feed wait.until
    '''
    elem_text = driver.find_element_by_id("viewed").text

    # Test to see if all of the values are ints
    if all(map(lambda x: x in ints, elem_text)):
        # If all of the char in the span are ints, return the value as an int
        return int(elem_text)
    else:
        return False

driver = webdriver.Chrome()
try:
    driver.get("http://your.url/here")
    int_value = WebDriverWait(driver, 30).until(custom_ec)
finally:
    driver.quit()
Sign up to request clarification or add additional context in comments.

1 Comment

I've tried this. works fine so far. I have no idea how to write a custom-expected_conditions before. thanks

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.