Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?

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

like image 458
Aarthi Avatar asked May 09 '17 10:05

Aarthi


People also ask

How do I resolve the Elementnotinteractableexception in Selenium WebDriver?

To resolve a temporary overspread, we can wait for an expected condition for the element. We can wait for the expected condition of invisibilityOfElementLocated for the overlay element. Or, wait for the expected condition of elementToBeClickable for the element with which we want to interact.

How do you resolve non Interactable elements?

To fix this, we can either apply explicit wait so that the webdriver waits for the expected condition - invisibilityOfElementLocated of the overlaying webelement. Or, we can apply the expected condition - elementToBeClickable on the webelement that we want to interact with.

How does Selenium handle element not displayed?

First Solution: Try to write unique XPATH that matches with a single element only. Second Solution: Use Explicit wait feature of Selenium and wait till the element is not visible. Once it is visible then you can perform your operations.

What will happen if a findElement type call can't find the element?

The Locator Strategy further accepts the Locator Value to identify a web element uniquely. If there is no matching element within the web page, findElement throws NoSuchElementException.


2 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.

  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); 
like image 123
undetected Selenium Avatar answered Sep 28 '22 01:09

undetected Selenium


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 :.(

like image 45
ProgrammingRookie Avatar answered Sep 28 '22 02:09

ProgrammingRookie