How to add a conditional wait on an element Python-Unitest?

How to add a conditional wait on an element Python-Unitest?

Hi Devan,

To add a conditional wait on an element Python-Unitest, you can refer to the sample code below for explicit waits. Since explicit waits allow you to wait for a condition to occur, they make a good fit for synchronizing the state between the browser and its DOM, and your WebDriver script.

from selenium.webdriver.support.ui import WebDriverWait
def document_initialised(driver):
    return driver.execute_script("return initialised")

driver.navigate("file:///race_condition.html")
WebDriverWait(driver, timeout=10).until(document_initialised)
el = driver.find_element(By.TAG_NAME, "p")
assert el.text == "Hello from JavaScript!"