How To Deal With “Element is not clickable at point” Exception Using Selenium

Posted by Shalini Baskaran | July 13, 2021
Automation • Selenium Java •

118126 Views | 8 Min Read

Element is not clickable at point

Any automation testing using Selenium (or Cypress) involves interacting with the WebElements available in the DOM. Selenium test automation framework underpins a diverse set of locators that are used to identify and interact with any type of element on the web page. For example, ID, name, className, XPath, cssSelector, tagName, linkText, and partialLinkText are some of the widely used Selenium Locators that help you interact with the elements on the web page. These locators help you perform any type of web element interactions using Selenium.

Source

Identifying the elements may be an easy task, but your tests might fail due to the state of the WebElement (e.g., not visible, not clickable, etc.). As a test automation engineer, it is important to consider these things to build a fool-proof test automation strategy.

In such cases, the tests might throw different types of exceptions like NoSuchElementException, ElementNotVisibleException, etc. This is often caused as the WebElement on the web page is not found, not interactable, or could be another issue with the corresponding WebElement. In this part of the Selenium Java tutorial, we would look at one of those exceptions – “Element is not clickable at the point.” By the end of the tutorial, you would be in a position to handle this exception like a pro!

What is the “Element is not clickable at point” exception?

The exception “Element is not clickable at point” usually occurs when the WebElement we want to interact with (or click) is not clickable at that point. This essentially means that the click operation on the WebElement would result in an exception. So, what are the causes of the exception? First, let’s deep dive into the various causes behind the “Element is not clickable at point” exception.

There is a higher probability of getting this exception with the Chrome browser, as Chrome never calculates the exact location of any WebElement. Instead, it tries to perform a click in the middle of the WebElement. Hence, you might get the “Element is not clickable at point.” exception when running tests on Chrome.

Does this mean that there is zero probability of witnessing this exception when running Selenium automation tests on Firefox, Microsoft Edge, or any other web browser? The underlying implementation differs from one browser to another. Hence, sometimes you may encounter this exception when clicking an element at a specific point (or coordinate).

What are the causes of the “Element is not clickable at point” exception?

In this section of the Selenium Java tutorial, let us understand the major causes of the “Element is not clickable at point” exception.

Below are the major causes of the exception:

  1. WebElement to be clicked is disabled.
  2. WebElement is not yet available (or loaded) on the web page.
  3. WebElements overlap with each other.
  4. Failure in locating WebElement using coordinates on the page.

Let us see the above causes in detail.

Cause 1: WebElement to be clicked is disabled

In a web application, if you skip filling any mandatory fields in a form or while creating an account, you would come across the Submit (or Create Account) in a disabled state.

When trying to interact with such a WebElement, the “Element is not clickable at point” exception pops up.

Cause 2: WebElement is not yet available (or loaded) on the web page

Most websites use AJAX for the dynamic loading of web content. Therefore, the test cases should be implemented considering this dynamism. You will encounter the said exception if the test script is trying to interact with the WebElement, which is not yet available in the DOM.

Read – How To Handle Synchronization In Selenium PHP Using Implicit and Explicit Wait?

Cause 3: WebElements overlap with each other

You might have overlapping WebElements on a webpage which poses significant challenges when running Selenium automation tests on the page. For example, when trying to interact with an element with another element overlapping it, it would throw the exception “Element is not clickable at point.”
Since this makes an interesting scenario, let’s look at a cross browser testing example which we would run on cloud-based Selenium Grid by LambdaTest. Running Selenium tests on a LambdaTest helps you attain better browser coverage, expedited test execution, and faster product release via integration with popular CI/CD tools. Furthermore, parallel testing is one of the major advantages of running tests on a cloud-based Grid like LambdaTest.

Read – Everything You Need To Know About Cloud Testing

For demonstration, we navigate to https://www.freecrm.com/ and log in by clicking the “Login” button.

WebElements overlap

Here is the code snippet that helps you realize the test scenario:

When running the above test, we encountered the “Element is not clickable at point” as the Login button is overlapped with another element.

pasted image

Here is the stack trace of the exception:

Cause 4: Failure in locating WebElement using coordinates on the page

Many times, you would need to identify the locators using their coordinates. The coordinates of the elements would differ depending upon the window size. Hence, it is a good practice to maximize the browser window when performing Selenium automation testing. You can read our detailed blog on Selenium Best Practices For Web Automation Testing to avoid issues you might frequently encounter when running Selenium tests.

Now that we have covered the different causes of the “Element is not clickable at point” exception, it’s time to deep dive into the potential solutions to avoid this exception.

cross browser-testing

How to fix the “Element Is Not Clickable at Point” exception?

There are some simple yet effective ways to resolve this exception. Let’s look at some of the ways to get rid of this exception in this part of the Selenium Java tutorial:

Solution 1: Adding Waits To Selenium Tests

To handle elements that take some time to load on the web page, you may add waits in Selenium. The added delay helps ensure that the WebElement to be interacted with is available on the web page. Have a look at the different Waits in Selenium that can help you achieve this task.

You can consider adding implicit waits, explicit waits, or fluent waits, depending upon the requirement. This would add some wait time for the WebElement(s) to load before performing interactions on the same.

For example, we can add explicit wait for a specific element so that it loads completely and is identified to be clickable.

Solution 2: Maximizing the browser window

When coordinates are used to identify the elements in the tests, it is always considered good practice to maximize your browser window. This ensures that the coordinates defined in your tests match with those on the page, as the browser is in the maximized state. Here is how you can avert the “Element is not clickable at point” exception by simply maximizing the web browser window:

Solution 3: Using JavascriptExecutor for performing mouse clicks

When the waits don’t help resolve the problem, you can use the JavascriptExecutor to perform the click operation.

JavaScriptExecutor is a key interface that allows you to execute JavaScript on the window or page of the browser using Selenium WebDriver. In addition, it provides methods to run JavaScript against the window (or page) from your test script.

Solution 4: Using Actions class in Selenium

The exception “Element is not clickable at point” might be thrown when the element is not under focus or the action is being performed on the incorrect WebElement. In such cases, you have to switch to the actual element and perform the click action.

To handle this scenario, use the Actions class in Selenium to switch to the specific element and performing the click operation as shown below:

You can also log onto the LambdaTest Community to get answers to questions like the “Element is not clickable at point” error and more. It’s time to leverage the expertise of the community to solve technical problems at an expedited pace!

For faster and improved test results, I would recommend a cloud-based Selenium Grid. LambdaTest is one such platform that provides cross browser testing on all major browsers and 2000+ operating systems online.

Read – Common Challenges In Selenium Automation & How To Fix Them?

Frequently Asked Questions

How do you check whether the element is clickable or not?

You can use the elementToBeClickable method for checking whether an element is visible and enabled such that you can click it.

How do you click on a non-clickable element in selenium?

To click a non-clickable element, first make sure that the overlapping element is closed. For example, to click an item in a column chart, first close the column containing it. Another solution is to switch to the layer that contains the element you want to click.

Conclusion

In this Selenium Java tutorial, we have seen how handling the elements in the automation test helps in successfully executing your tests. Every one of us would have faced multiple exceptions while executing our automation test suite and might have found a resolution to fix it.

Source

This article focuses on one such exception and the fixes to overcome it. I hope you find this article useful and a guide to overcoming the exception.

Happy Testing 🙂

Written by

Related Articles

Handle Cookies in Selenium

How To Handle Cookies in Selenium WebDriver

7094 Views | 10 Min Min Read

JUnit Test Using TestNG

How To Run JUnit Selenium Tests using TestNG

16292 Views | 2 Min Min Read

TDD vs. BDD: Choosing The Right Framework

138076 Views | 19 Min Min Read

Leave a Reply

Your email address will not be published. Required fields are marked *