Ancora Imparo - I'm still learning (Michelangelo at 87)

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

ElementNotInteractableException is one of the few notable exceptions encountered in the Selenium WebDriver. This W3C exception is thrown to outline how, regardless of the presence of an element in the HTML DOM, it still can’t be interacted with. This is evident in the inability to click or send keys, functions which make running the Selenium WebDriver possible. There are many root causes which may be attached to this problem; the prominent ones are element invisibility or non-display and hidden element behind another. Through this article, we will outline the few steps you can take to rectify this issue.

Temporary Overlay of other WebElement over the WebElement of our interest

When this problem has been identified as the root cause, the most effective way to resolve this is to execute ExplicitWait by combining WebDriverWait and ExpectedCondition as invisibilityOfElementLocated. A sample of this is analyzed below:

WebDriverWait wait2 = new WebDriverWait(driver, 10);

Another way to go about solving this problem is by approaching it on a more granular level by using ExpectedCondition as elementToBeClickable as opposed to using ExpectedCondition as invisibilityOfElementLocated. This is analyzed below:

WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));;

Permanent Overlay of other WebElement over the WebElement of our interest

The best solution for this type of problem is by casting the WebDriver instance as if the overlay is a permanent one. In this case, we have to cast the WebDriver instance as JavascriptExecutor followed by a click operation. This step is analyzed below:

WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

Other general ways of solving the ElementNotInteractableException include:

  • Waiting until an element is visible/clickable
WebDriverWait wait = new WebDriverWait(driver, timeout);
  • Scroll until the element is within the display
Actions action = new Actions(driver):
  • Utilizing JS Executor to interact with the DOM
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("var element = document.querySelector('locator');element.value = 'whatever';")

About the Autor

Jamiu Idowu

Jamiu Idowu

Entrepreneur seeking to shape the world through IT and emerging technologies. Enjoys research and technical writing, and can serve as a bridge between technology and its users.

Liked this article?

We have a lot more where that came from!
Join the subscribers who stay ahead of the pack.

By entering your email, you agree to our Terms of Service and Privacy Policy.