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();