Back to All Scenarios
Scenario 14 of 100
Synchronization
Beginner
Wait Until Loader or Spinner Disappears
β³Scenario Overview
Wait Until Loader or Spinner Disappears
Key Takeaways & Cheat Sheet
- βIdentify the loader element class or overlay ID in the DOM
- βUse ExpectedConditions.invisibilityOfElementLocated for automatic wait
- βDecrease implicit wait temporarily if checking for immediate overlay presence
- βVerify loader is completely detached from the DOM to avoid intercepts
Short Direct Answer
When pages fetch data dynamically, a loader, spinner, or backdrop modal blocks user interaction. Attempting to click background elements will fail. To resolve this, always identify the spinner element and apply an explicit wait for its complete invisibility or detachment before proceeding with functional test steps.
β οΈ Senior Warning (Red Flag)
Never click the target element while a loader is semi-transparent or fade-out animating. Always wait for full loader invisibility or detachment.
π‘ STAR Deep Dive Explanation & Pro Tip
Using invisibilityOfElementLocated is highly optimized because it continues immediately once the spinner disappears, minimizing test latency compared to static sleep intervals.
SeleniumAutomation.java
Selenium 4 + Java// β
Wait explicitly for loader element invisibility
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".loading-spinner")));
// β
Proceed with clicking target element
driver.findElement(By.id("submit-btn")).click();