SneakersSO
SneakersSO

Reputation: 85

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)
        driver.refresh()
        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")

Upvotes: 0

Views: 1549

Answers (1)

lasagne.victim
lasagne.victim

Reputation: 102

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):
    driver.refresh()
    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.

Upvotes: 2

Related Questions