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 #"));// 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"))
)
);Key Point: Always wait for spinners to vanish before clicking, and use ExpectedConditions.refreshed() to survive DOM re-renders.