- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to resolve exception Element Not Interactable Exception in Selenium?
We can resolve the exception – ElementNotInteractableException with Selenium webdriver. This exception is thrown if a webelement exists in DOM but cannot be accessed. The below image shows an example of such an exception.
If a specific webelement is overspread by another webelement we normally get this exception. 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. To resolve a permanent overlay, we have to use the JavaScript Executor to perform the click action. Selenium utilizes the executeScript method to run JavaScript commands.
Syntax
WebDriverWait wait= (new WebDriverWait(driver, 5)); wait.until(ExpectedConditions . elementToBeClickable (By.id("element id"))); //alternate solution wait.until(ExpectedConditions. invisibilityOfElementLocated(By.id("overlay element id"))); //fix with JavaScript executor WebElement m = driver.findElement(By.id("element id")); JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("arguments[0].click();", m);
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.JavascriptExecutor; public class InteractableExceptResolve{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //launch URL driver.get("https://login.yahoo.com/"); //identify element WebElement m = driver.findElement(By.xpath("//input[@id='persistent']")); //JavascriptExecutor to click element JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("arguments[0].click();", m); boolean b = m.isSelected(); if (b) { System.out.println("Checkbox is not checked"); }else { System.out.println("Checkbox is checked"); } driver.close(); } }
Output
- Related Articles
- How to Resolve Stale Element Reference Exception in Selenium WebDriver?
- What is Stale Element Reference Exception in Selenium Webdriver & How To Fix It?
- Selenium Exception Error - Element is not clickable at point (x,y). Other element would receive the click
- Which exception is raised when an element is not found in an HTML DOM using XPath in Selenium?
- How to capture file not found exception in Java?
- How to capture file not found exception in C#?
- How to create a user defined exception (custom exception) in java?
- How to handle an exception in Python?
- How to catch KeyError Exception in Python?
- How to raise an exception in Python?
- How to catch IOError Exception in Python?
- How to catch ArithmeticError Exception in Python?
- How to catch OverflowError Exception in Python?
- How to catch IndexError Exception in Python?
- How to catch NameError Exception in Python?
