Here I have the image of my code and the image of my error. Can anyone help me to resolve this issue?
-
1You 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– Kushal BhalaikCommented May 9, 2017 at 15:09
-
14Please do not post images of text, rather keeping as text.– SiKingCommented Aug 9, 2017 at 22:18
6 Answers
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.
Temporary Overlay of other
WebElement
over theWebElement
of our interest :In this case, the direct solution would have been to induce
ExplicitWait
i.e.WebDriverWait
in combination withExpectedCondition
asinvisibilityOfElementLocated
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
asinvisibilityOfElementLocated
we can useExpectedCondition
aselementToBeClickable
as follows:WebDriverWait wait1 = new WebDriverWait(driver, 10); WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked"))); element1.click();
Permanent Overlay of other
WebElement
over theWebElement
of our interest :If the overlay is a permanent one in this case we have to cast the
WebDriver
instance asJavascriptExecutor
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);
-
10This 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.– peepaCommented Jun 7, 2018 at 13:01
-
2For 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? Commented Dec 29, 2020 at 16:50 -
2excellent! permanent overlay is very common no matter what we try sometimes.– imbrCommented Aug 4, 2022 at 16:45
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 :.(
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.
Try using the Implicit wait:
driver.manage().timeouts().implicitlyWait(Time, TimeUnit.SECONDS);
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);
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
-
3Never 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. Commented Jun 14, 2019 at 12:59
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));
-
I also that one also. But it doesn't work. Could you please tell me some other way to solve this issue?– AarthiCommented 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.– JeffCCommented 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 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
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')