---
title: Selenium & ElementClickInterceptedException
description: What causes an ElementClickInterceptedException in Selenium, how it differs
  from the other click failures, and how to handle it reliably.
source_url:
  html: https://testingbot.com/resources/articles/selenium-elementclickinterceptedexception
  md: https://testingbot.com/resources/articles/selenium-elementclickinterceptedexception.md
---

![Selenium & ElementClickInterceptedException](https://testingbot.com/assets/resources/articles/33.webp)

# Handling ElementClickInterceptedException with Selenium

What causes an ElementClickInterceptedException in Selenium, how it differs from the other click failures, and how to handle it reliably.

By [Jochen D.](https://testingbot.com/about/jochen-d)2023-09-26

 Share on Facebook 

 Share on Twitter 

 Post on Reddit 

 Share link 

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.

## Table of Contents

- [What is an ElementClickInterceptedException?](https://testingbot.com#what)
- [What can cause an ElementClickInterceptedException?](https://testingbot.com#cause)
- [How can I handle an ElementClickInterceptedException in Selenium?](https://testingbot.com#handle)

## 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.

## How can I handle an ElementClickInterceptedException in Selenium?

Handling an **ElementClickInterceptedException** in Selenium involves adding strategies to wait for DOM elements to become clickable. You'll also need to handle situations where elements are intercepted or obscured by other elements in the DOM tree.

### Use Explicit Waits

You can use explicit waits, with expected conditions, to make sure that the element is clickable, before Selenium attempts to click it. See the Java example below.

```java
import org.openqa.selenium.*;

public class ElementClickInterceptException {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 10);

        // Replace this with the DOM element you are trying to click
        By elementLocator = By.id("clickMyElement");

        driver.get("https://testingbot.com");

        try {
            WebElement element = wait.until(ExpectedConditions.elementToBeClickable(elementLocator));
            element.click(); // once the element is clickable, you can click it
        } catch (Exception e) {
            // The element was not clickable, handle it appropriately
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }
}
```

### Add a Retry Mechanism to your test

You can add a retry mechanism to handle the ElementClickInterceptedException.. Simply catch the ElementClickInterceptedException during your test. Then wait for a specific amount of time, or hide/remove any overlapping elements. Finally, retry the click action.

```java
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.WebDriverWait;

public class RetryMechanismExample {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 10);

        // Replace this with the DOM element you are trying to click
        By elementLocator = By.id("clickMyElement");
        
        driver.get("https://testingbot.com");

        int maxAttempts = 3; // Maximum number of times you want to retry
        int attempt = 1;
        boolean elementClickable = false;

        while (attempt <= maxAttempts) {
            try {
                WebElement element = wait.until(ExpectedConditions.elementToBeClickable(elementLocator));
                element.click(); // Click the element once it becomes clickable
                elementClickable = true; // Set the flag to indicate it was clicked
                break; // Break the loop since the action was successful
            } catch (Exception e) {
                // Not clickable, maybe retry?
                attempt++; // Increment the attempt count
            }
        }

        if (!elementClickable) {
            System.out.println("Element was not clickable after " + maxAttempts + " attempts. Try a different strategy?");
        }
        driver.quit();
    }
}
```

### Scroll the Element into View

If the element is not visible on the page, because it's not in the viewport, then you can scroll it into view before attempting to click on it.

```java
driver.execute_script("arguments[0].scrollIntoView();", element)
element.click()
```

### Handling any Overlapping Elements

If you know there are overlapping elements on the page, you can first hide/remove these from the DOM before you attempt to click.

### Use the Selenium Actions Class

You could use the Selenium Action Class, which allows you to combine multiple user gestures. For example, combine moving to the element and then clicking the element in one action.

```java
import org.openqa.selenium.*;

public class ActionsClickExample {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        Actions actions = new Actions(driver);

        // Replace this with the DOM element you are trying to click
        By elementLocator = By.id("clickMyElement");

        driver.get("https://testingbot.com");

        WebElement element = driver.findElement(elementLocator);
        actions.moveToElement(element).click().build().perform();

        driver.quit();
    }
}
```

## Sidebar

### TestingBot Cloud Testing

Run automated, manual and visual tests on remote browsers and devices. Sign up for a free trial.

[Free Trial](https://testingbot.com/users/sign_up)

### Latest articles

[![Record tests with Playwright](https://testingbot.com/assets/resources/articles/32-277318b88c5e35eb2c96f03d9b53a1ef8eb2d96db184679892b5008b0bad9d0f.webp)](https://testingbot.com/resources/articles/playwright-recorder)

#### [Record tests with Playwright](https://testingbot.com/resources/articles/playwright-recorder)

How to record Playwright scripts from Visual Studio Code ...

[Read article →](https://testingbot.com/resources/articles/playwright-recorder)

[![Testing with React and Selenium](https://testingbot.com/assets/resources/articles/31-744de7cfd83a956722f63fdccfc836d4cd8ee5182785fd84f7bbabe3a40e1615.webp)](https://testingbot.com/resources/articles/react-selenium-testing)

#### [Testing with React and Selenium](https://testingbot.com/resources/articles/react-selenium-testing)

How to test a React site with both React Testing Library ...

[Read article →](https://testingbot.com/resources/articles/react-selenium-testing)

[![How to fix Flaky Tests](https://testingbot.com/assets/resources/articles/30-da23ef05df0b04704e23e77b3b068cc04d038f42ca12ae7123c8039acf5fb41d.webp)](https://testingbot.com/resources/articles/handling-test-flakiness)

#### [How to fix Flaky Tests](https://testingbot.com/resources/articles/handling-test-flakiness)

Why a test passes most of the time and fails the rest, wi...

[Read article →](https://testingbot.com/resources/articles/handling-test-flakiness)

## Other Articles

[![Record tests with Playwright](https://testingbot.com/assets/resources/articles/32-277318b88c5e35eb2c96f03d9b53a1ef8eb2d96db184679892b5008b0bad9d0f.webp)](https://testingbot.com/resources/articles/playwright-recorder "Record tests with Playwright")

### [Record tests with Playwright](https://testingbot.com/resources/articles/playwright-recorder)

How to record Playwright scripts from Visual Studio Code rather than writing them by hand, then run the recorded tests on a browser grid.

[Read article →](https://testingbot.com/resources/articles/playwright-recorder)

[![Testing with React and Selenium](https://testingbot.com/assets/resources/articles/31-744de7cfd83a956722f63fdccfc836d4cd8ee5182785fd84f7bbabe3a40e1615.webp)](https://testingbot.com/resources/articles/react-selenium-testing "Testing with React and Selenium")

### [Testing with React and Selenium](https://testingbot.com/resources/articles/react-selenium-testing)

How to test a React site with both React Testing Library and Selenium WebDriver, and when each of the two is the right tool to reach for.

[Read article →](https://testingbot.com/resources/articles/react-selenium-testing)

[![How to fix Flaky Tests](https://testingbot.com/assets/resources/articles/30-da23ef05df0b04704e23e77b3b068cc04d038f42ca12ae7123c8039acf5fb41d.webp)](https://testingbot.com/resources/articles/handling-test-flakiness "How to fix Flaky Tests")

### [How to fix Flaky Tests](https://testingbot.com/resources/articles/handling-test-flakiness)

Why a test passes most of the time and fails the rest, with concrete fixes for flaky Selenium, Appium, Playwright and Puppeteer runs.

[Read article →](https://testingbot.com/resources/articles/handling-test-flakiness)

[![Test Automation with ChatGPT](https://testingbot.com/assets/resources/articles/29-7c01b99e7284a560ad99094e3ce738c4942eee113a51295a0a8e9cd8fe0cbba5.webp)](https://testingbot.com/resources/articles/test-automation-with-chatgpt "Test Automation with ChatGPT")

### [Test Automation with ChatGPT](https://testingbot.com/resources/articles/test-automation-with-chatgpt)

How to prompt ChatGPT into generating Selenium, Appium, Puppeteer and Playwright tests, and how far the output can be trusted as written.

[Read article →](https://testingbot.com/resources/articles/test-automation-with-chatgpt)

## Ready to start testing?
[Start a free trial](https://testingbot.com/users/sign_up)
