How do I resolve the ElementNotInteractableException in Selenium WebDriver?
Hi Rhian,
Hi There, ElementNotInteractableException occurs when an element is found, but you can’t be interacted with. For instance, you may not be able to click or send keys. This could happen due to various reasons like the element being not visible or displayed, the element being off-screen or the element being behind another element or hidden. So, you can perform some of the actions to make the element interactable:
- Wait until an element is visible/clickable
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOf(element));
wait.until(ExpectedConditions.elementToBeClickable(element));
- Scroll until the element is within the display
Actions action = new Actions(driver);
action.moveToElement(element);
- Use JS Executor to interact directly with the DOM
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("var element = document.querySelector('locator'); element.value = 'whatev