πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
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();