- 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 do I resolve the ElementNotInteractableException in Selenium WebDriver?
We get the ElementNotInteractableException in Selenium if an element is available in DOM but not in a condition to be interacted. Some of the reasons for this exception are −
There may be a covering of another element on the element with which we want to interact with. This overspread of an element over the other can be temporary or permanent. 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.
Syntax
WebDriverWait w= (new WebDriverWait(driver, 7)); w.until(ExpectedConditions . elementToBeClickable (By.id("id of element"))); //alternate solution w.until(ExpectedConditions . invisibilityOfElementLocated(By.id("id of overlay element")));
To resolve a permanent overspread, we can use the JavaScript Executor to perform the click action. Selenium uses the executeScript method to execute JavaScript commands.
Syntax
WebElement l = driver.findElement(By.id("id of element")); JavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("arguments[0].click();", l);
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 InteractableExceptionFix{ 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 l = driver.findElement(By.xpath("//input[@id='persistent']")); //JavascriptExecutor to click element JavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("arguments[0].click();", l); boolean t = l.isSelected(); if (t) { System.out.println("Checkbox is not checked"); }else { System.out.println("Checkbox is checked"); } driver.quit(); } }
Output
- Related Articles
- How do I open Chrome in selenium WebDriver?
- How do I set the Selenium webdriver get timeout?
- How to Resolve Stale Element Reference Exception in Selenium WebDriver?
- How do I get current URL in Selenium Webdriver 2 Python?
- How do I set browser width and height in Selenium WebDriver?
- How do I find an element that contains specific text in Selenium Webdriver?
- How to do session handling in Selenium Webdriver?
- How do I find an element that contains specific text in Selenium WebDriver (Python)?
- What can selenium WebDriver do?
- How do I get a parent HTML Tag with Selenium WebDriver using Java?
- How can I get Webdriver Session ID in Selenium?
- How can I handle multiple keyboard keys using Selenium Webdriver?
- How do you automatically download a Pdf with Selenium Webdriver in Python?
- How do I use Selenium IDE?
- How do I download Selenium RC?
