'Selenium-Python: How do I make my WebDriverWait a few seconds before reloading a page?

So I have a section of code that checks a part of a webpage to see if the status has been changed to get to the next step in the script. It refreshes the page if it hasn't, and ideally, I would like the script to wait at this webpage for about 5-10 seconds before it refreshes the page again. Here is my current loop for this:

orderElem = driver.find_element(By.CSS_SELECTOR, "dd.Production.Status")

while(orderElem.text != "Output Complete"):
        WebDriverWait(driver, 10)
        WebDriverWait(driver, 5).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "dd.Production.Status"))
        orderElem = driver.find_element(By.CSS_SELECTOR, "dd.Production.Status")

Solution 1:[1]

You can explicitly just wait with time.sleep(10) instead of WebDriverWait.

It seems like you are trying to refresh-poll the page every 10 second until orderElem.text == 'Output Complete', in which case:

def until_func(driver):
    elem = driver.find_element_by_css_selector("dd.Production.Status")
    if elem.is_displayed() and elem.text == 'Output Complete':
        return elem
orderElem = WebDriverWait(driver, timeout=60, poll_frequency=10).until(until_func)

This will refresh the page every 10s, check if element desired is visible and has the correct text, and return the element when those conditions are met.


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lasagne.victim