In this article we'll study the ElementClickInterceptedException, which is an exception that may occur during your Selenium tests.
ElementClickInterceptedException is part of a collection of exceptions that Selenium might throw during your test. Other exceptions such as NoSuchElementException
, TimeoutException
, SessionNotCreatedException
, StaleElementReferenceException
and ElementClickInterceptedException
each deserve their own article.
What is an ElementClickInterceptedException?
An ElementClickInterceptedException is a type of exception which can occur when using Selenium to run a test. The exception is usually thrown when an attempt to click on an element on a web page is intercepted or blocked by another element. Usually this happens when another element is overlapping or positioned (partly) in front of the DOM element that your Selenium script is trying to click.
ElementClickInterceptedException is a Java-specific exception when running Selenium tests through the Java bindings. The same type of exception is available in the other Selenium bindings, with different names:
Selenium Binding | Exception name |
---|---|
Java | ElementClickInterceptedException |
JavaScript | WebDriverError: element click intercepted |
C#/.NET | OpenQA.Selenium.ElementClickInterceptedException |
Ruby | ERROR: element click intercepted |
Python | selenium.common.exceptions.ElementClickInterceptedException |
What can cause an ElementClickInterceptedException?
Below is a list of the most common scenarios that may lead to this type of exception.
-
Overlapping Elements
For example, when multiple DOM elements overlap on a web page and the DOM element you want to click is obscured by another element. The most common elements that may cause such behaviour are popups, modal dialogs, advertisements or overlapping buttons.
-
Animations and Transitions
DOM Elements might move during a CSS animation or transition, while your test is trying to interact with an element. This may cause problems for Selenium to click the element.
-
Timing Problems
ElementClickInterceptedException can occur if the Selenium test script attempts to click an element before it becomes clickable or visible on the page.