35

Here I have the image of my code and the image of my error. Can anyone help me to resolve this issue?

enter image description here

enter image description here

2
  • 1
    You should try to isolate element you want to interact with. in your code there are multiple elements having <input> tag; so its better if you use specific path to that element Commented May 9, 2017 at 15:09
  • 14
    Please do not post images of text, rather keeping as text.
    – SiKing
    Commented Aug 9, 2017 at 22:18

6 Answers 6

68

ElementNotInteractableException

ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the HTML DOM, it is not in a state that can be interacted with.

Reasons & Solutions :

The reason for ElementNotInteractableException to occur can be numerous.

  1. Temporary Overlay of other WebElement over the WebElement of our interest :

    In this case, the direct solution would have been to induce ExplicitWait i.e. WebDriverWait in combination with ExpectedCondition as invisibilityOfElementLocated as folllows:

    WebDriverWait wait2 = new WebDriverWait(driver, 10);
    wait2.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("xpath_of_element_to_be_invisible")));
    driver.findElement(By.xpath("xpath_element_to_be_clicked")).click();
    

    A better solution will be to get a bit more granular and instead of using ExpectedCondition as invisibilityOfElementLocated we can use ExpectedCondition as elementToBeClickable as follows:

    WebDriverWait wait1 = new WebDriverWait(driver, 10);
    WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
    element1.click();
    
  2. Permanent Overlay of other WebElement over the WebElement of our interest :

    If the overlay is a permanent one in this case we have to cast the WebDriver instance as JavascriptExecutor and perform the click operation as follows:

    WebElement ele = driver.findElement(By.xpath("element_xpath"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", ele);
    
4
  • 10
    This should be marked as correct answer, but for #2 it needs to be said, that there might be a reason why the overlay is there. In such case one needs to consider, whether getting around it with javascript executor is not actually getting around an unexpected behavior of app.
    – peepa
    Commented Jun 7, 2018 at 13:01
  • 2
    For future readers of this thread: An example of "numerous possibilities" as @DebanjanB states, turned out in my case to be, that an <a> link that was in a <details> block that was 'closed' was being clicked on; 'click'ing the <details> block open and then 'click'ing the <a> link resolved the issue! Commented Apr 25, 2019 at 10:36
  • does someone know how to realize ExpectedConditions in Javascript please?
    – Don Diego
    Commented Dec 29, 2020 at 16:50
  • 2
    excellent! permanent overlay is very common no matter what we try sometimes.
    – imbr
    Commented Aug 4, 2022 at 16:45
3

I got this because the element I wanted to interact with was covered by another element. In my case it was an opaque overlay to make everything r/o.

When trying to click an element UNDER another element we usualy get "... other Element would receive the click " but not always :.(

2

This Exception we get when the element is not in an interactable state. So we can use wait till the element is Located or become clickable.

  1. Try using the Implicit wait:

    driver.manage().timeouts().implicitlyWait(Time, TimeUnit.SECONDS);
    
  2. If this is not working use Explicit wait:

    WebDriverWait wait=new WebDriverWait(driver, 20);
    WebElement input_userName;
    input_userName = wait.until(ExpectedConditions.elementToBeClickable(By.tagName("input")));
    input_userName.sendkeys("suryap");
    

You can use ExpectedCondition.visibilityOfElementLocated() as well. You can increase the time, for example,

WebDriverWait wait=new WebDriverWait(driver, 90);
0

A solution to this for Javascript looks like this. You will have to modify the time to suit your need.

driver.manage().setTimeouts({ implicit: 30000 });

Hope this is helpful to someone. see the docs for reference

1
  • 3
    Never use sleep() or setTimeout() to wait for an event. It's a bad practice and you'll end up with a situation where your code randomly stops working when you deploy it on a new machine, but it was working perfectly until then. Events should be handled by waiting operations, designed to wake up your code as soon as the condition has been met or a timeout occurred.
    – Mladen B.
    Commented Jun 14, 2019 at 12:59
0

Actually the Exception is Element Not Visible

The best practice is to use Implicit wait below driver Instantiation so it get sufficient time to find element throughout the exception

driver.get("http://www.testsite.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

Still facing issue as some element require more time. Use ExplicitWait for individual element to satisfy certain condition

In your case you are facing element not visible exception then use wait condition in following way-

WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.your_Elemetnt));
7
  • I also that one also. But it doesn't work. Could you please tell me some other way to solve this issue?
    – Aarthi
    Commented May 10, 2017 at 11:18
  • Implicit wait is not a best practice. In fact it's use is recommended against by the Selenium contributors. Also mixing implicit and explicit waits is warned against in the official docs.
    – JeffC
    Commented Nov 4, 2017 at 3:56
  • Wait is not a solution... in my case i need to click on ant UI time picker component. Waiting is not a solution and im still looking for workaround Commented Jul 16, 2020 at 17:03
  • @user1767083 Obviously wait is not a solution for each problem. Post a separate question with appropriate details on SO. You will definitely get a solution. Thanks
    – NarendraR
    Commented Jul 16, 2020 at 18:04
  • @NarendraR this is the problem i face, stackoverflow.com/questions/62907372/… Commented Jul 17, 2020 at 7:51
0

In my case issue was because there is some animation, and that element is not visible for some duration. And hence exception was occurring.

For some reason I couldn't make ExpectedConditions.visibilityOfElementLocated work, so I created a code to wait for some hardcoded seconds before proceeding.

from selenium.webdriver.support.ui import WebDriverWait


def explicit_wait_predicate(abc):
    return False


def explicit_wait(browser, timeout):
    try:
        Error = WebDriverWait(browser, timeout).until(explicit_wait_predicate)
    except Exception as e:
        None

And now I am calling this explicit_wait function wherever I want to wait for sometime e.g.

from selenium import webdriver
from selenium.webdriver.common.by import By


browser = webdriver.Safari()
browser.get('http://localhost')

explicit_wait(browser,5)   # This will wait for 5 secs
elem_un = browser.find_element(By.ID, 'userName')  

Not the answer you're looking for? Browse other questions tagged or ask your own question.