By Shivam Singh, founder of TesterRank · Updated September 2026
In real apps, most timing problems come from a few repeating patterns: loading spinners that cover the page, lists that re-render after a filter, and buttons that are disabled until a form is valid. Once you recognise the pattern, you know which wait to use.
Let us examine the exact wait patterns you will implement when automating production applications like banking, e-commerce, and travel portals:
When submitting a transaction, applications display a full-page loading spinner. If you try to interact with dashboard elements while the spinner is active, Selenium throws ElementClickInterceptedException. The solution is a two-step explicit wait:
driver.findElement(By.id("submit-payment-btn")).click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
// Step 1: Wait for spinner overlay to completely disappear from viewport
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".payment-loading-spinner")));
// Step 2: Now wait for transaction receipt to become visible
WebElement receipt = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("transaction-receipt")));
Assert.assertTrue(receipt.getText().contains("Reference #"));A stale element is one the page has redrawn since you found it. The fix is to find the element again after any action that changes the page, instead of reusing the old reference.
// Avoid caching elements across DOM-mutating actions
// Click 'Apply Promo Code' — page re-renders price summary
driver.findElement(By.id("apply-coupon-btn")).click();
// Wait for the refreshed element state dynamically
WebElement updatedTotal = wait.until(
ExpectedConditions.refreshed(
ExpectedConditions.visibilityOfElementLocated(By.id("cart-total-amount"))
)
);| What you see | Why it happens | What to wait for |
|---|---|---|
| Click does nothing | An overlay or spinner is on top | invisibilityOfElementLocated(spinner), then click |
| Button is greyed out | Form is not valid yet | elementToBeClickable(button) |
| StaleElementReferenceException | List re-rendered after an action | Find the element again after the update |
| Old text still shown | Data loads after the page | textToBePresentInElementLocated or a custom condition |
| New tab opens slowly | Browser is creating the window | numberOfWindowsToBe(2) |
Practice these on the Shopping portal: apply a filter in the catalog, then wait for the product list to update before you count the results.
Before writing a wait, describe in one sentence what the page is doing after your action. For example: "After I click Search, a spinner appears, the old results disappear, and new results load." That sentence tells you exactly what to wait for: the spinner to disappear, or the first new result to appear. Testers who describe the page first write fewer flaky tests than testers who guess timeouts.
Key Point: Always wait for spinners to vanish before clicking, and use ExpectedConditions.refreshed() to survive DOM re-renders.