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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

1 thought on “ElementNotInteractableException – element not interactable

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.

ElementNotInteractableException – element not interactable

by Amod Mahajan time to read: 3 min
1
%d bloggers like this: