Schedule task keeps repeating and never stops

Question:

def refresh_page():
    driver.refresh()

time.sleep(2)
while True:
    if driver.find_element(By.CLASS_NAME, "mask2").is_displayed() == True:
        break
    schedule.every(1).minute.at(":00").do(refresh_page)
    
    schedule.run_pending()
    time.sleep(1)

I was expecting it to only run the schedule command once, well it did work when it was not on ":00" seconds but as soon as it hits ":00" it keeps doing the task whenever it’s possible to do so. Btw the element is not displayed and I checked it so it could not be that line that’s causing the problem (I think)

Asked By: Momorenosas

||

Answers:

I think you need to put scheduling outside while loop, since it schedules multiple times:

def refresh_page():
    driver.refresh()

time.sleep(2)
schedule.every(1).minute.at(":00").do(refresh_page)
while True:
    if driver.find_element(By.CLASS_NAME, "mask2").is_displayed() == True:
        break
    
    schedule.run_pending()
    time.sleep(1)
Answered By: godot