Make Selenium Easy

ElementNotInteractableException – element not interactable

ElementNotInteractableException – A very common exception which occurs in Selenium WebDriver scripts. We will replicate the same scenario and then will solve it.

Scenario

  1. Open Google.
  2. Type “Facebook” in search box.
  3. Click on first result from auto suggestion list.
  4. Verify title of page.

Let’s write an XPath for first option from auto suggestion as –

Simple steps and below is code :-

Output

When people get this exception then they will start experimenting by putting some wait or wait for clickable or JavaScript click. In this scenario only JavaScript click may work as it directly works at DOM level but we bypassed the actual reason.

Let me explain the reason behind occurrence of this exception.

As per official doc –

ElementNotInteractableException is Thrown to indicate that although an element is present on the DOM, it is not in a state that can be interacted with.

If you see the XPath of first option from auto suggestions, we are instructing WebDriver to perform Click on a span tag. But is span tag a clickable element above? Answer is No for above scenario and we ended up with ElementNotInteractableException. Please note a span or div can be made clickable.

Observe DOM. Tag “li” is clickable above not tag “span“. WebDriver can perform operation on an element if element is in state that can be interacted.

Let’s correct our XPath which locates li tag instead of span.

This time scripts run successfully.

This exception may occur in many scenarios when an element is disabled or element is nested. All you need to observe your DOM well so that you can catch root cause instead of trying some workarounds blindly.

You can download/clone above sample project from here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.

Many other topics you can navigate through menu.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

3 thoughts on “ElementNotInteractableException – element not interactable

  1. I need to work with a webelement which is hidden inside a form tag like this where in i have to pass a value. I am getting ElementNotInteractableException. How can we handle this kind of scenario other than correcting xpath ?

    Thanks !

  2. Thank you very much Amod, it quite simple to understand this exception along with an example scenario.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.