In short
Most flaky UI tests aren't caused by bugs. They're caused by a script clicking before the page is ready. Waiting the right way fixes the biggest headache in automation.
Ensuring a script waits for a page or element to be ready before interacting with it — the single most common source of flaky, unreliable automated tests when handled incorrectly.

Think of it like this
The railway crossing gate
You don't count to 300 and then ride across. You wait until the gate actually lifts. Sometimes that's one minute, sometimes ten. A good wait watches for a condition, not a clock.
Watch it happen
An explicit wait polling the page
click Start
1/6The click starts a slow load. The result appears a few seconds later.
The big ideas
What you need to know
sleep is a guess
time.sleep(5) is too long on fast days and too short on slow ones. Avoid it.
Explicit waits
WebDriverWait plus a condition like visibility or clickability waits only as long as needed.
Don't mix waits
Selenium's docs warn against mixing implicit and explicit waits. It can cause long, unpredictable delays.
Sensible timeouts
Pick a limit like 10 seconds. If it times out, that's a real signal worth investigating.
See it in code
Walk through the code
1from selenium import webdriver2from selenium.webdriver.common.by import By3from selenium.webdriver.support.ui import WebDriverWait4from selenium.webdriver.support import expected_conditions as EC5 6driver = webdriver.Chrome()7driver.get("https://the-internet.herokuapp.com/dynamic_loading/1")8driver.find_element(By.CSS_SELECTOR, "#start button").click()9 10wait = WebDriverWait(driver, 10)11finish = wait.until(EC.visibility_of_element_located((By.ID, "finish")))12 13assert finish.text == "Hello World!"14driver.quit()1/3Clicking Start triggers a loading bar that takes a few seconds.
The text is in the page but hidden while loading, so we wait for it to become visible.
Save yourself the pain
Common mistakes
Oops
Adding time.sleep(10) everywhere until the test stops failing.
Do this instead
Wait for a specific condition, like visibility or clickability, with WebDriverWait.
Oops
Waiting for an element to exist when it's present but hidden.
Do this instead
Pick the right condition: presence, visibility and clickability are different things.
Your mission
Kill a flaky test
Quick check
Why is an explicit wait better than time.sleep(5)?
Go deeper
- 1Replace a hardcoded sleep() in a script with an explicit wait condition.
- 2Learn the difference between implicit waits, explicit waits, and fixed sleeps.
- 3Understand why fixed sleeps are almost always the wrong choice — too slow or too fragile.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.