πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 17 of 100
Exceptions
Intermediate

Resolving ElementClickInterceptedException

πŸ’₯Scenario Overview

Resolving ElementClickInterceptedException

Key Takeaways & Cheat Sheet

  • βœ“Identify overlapping overlays, sticky headers, or modal backdrops
  • βœ“Wait for the intercepting element to become invisible or fully closed
  • βœ“Scroll the element into view explicitly using JavascriptExecutor
  • βœ“Use JavaScript Click only as a fallback when physical click is impossible

Short Direct Answer

ElementClickInterceptedException is thrown when you attempt to click an element but another element covers it at the exact coordinates (e.g. a cookie banner, loading dialog, or sticky header). To resolve this, identify the overlapping element and wait for it to disappear, scroll the target element to the center of the viewport, or use a JavaScript click as a controlled fallback.

⚠️ Senior Warning (Red Flag)

Do not use Javascript Executor clicks blindly. It bypasses physical limitations, meaning your test will pass even if the user cannot physically click the button, lowering testing reliability.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

Inspecting screenshots on failure is key. If a banner is covering the button, add code to close the banner first.

SeleniumAutomation.java
Selenium 4 + Java
// βœ… Resolve sticky header overlap by scrolling to center
WebElement targetBtn = driver.findElement(By.id("checkout-btn"));
((JavascriptExecutor) driver).executeScript(
    "arguments[0].scrollIntoView({block: 'center'});", targetBtn
);

// βœ… Ensure element is fully clickable
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.elementToBeClickable(targetBtn)).click();