'Selenium Error : org.openqa.selenium.InvalidElementStateException: invalid element state

I am getting invalid element state when I try to clear element after click.

Following are operations I am doing on element:

inputField.click();
inputField.clear();
inputField.sendKeys("name");

The first step click is working fine, but clear is giving exception:

org.openqa.selenium.InvalidElementStateException: invalid element state

There is another test case, which calls the method which has above three steps and it works fine.What can be potential issue?



Solution 1:[1]

InvalidElementStateException

InvalidElementStateException implies that a WebElement is in a certain state when actions cannot be performed with it. One of the most frequently encountered examples would include an element being obscured by another when clicking, or perhaps not being visible on the HTML DOM.


This usecase

As you are trying to click(), clear() and sendKeys() within the WebElement ideally you need to induce WebDriverWait for the elementToBeClickable() and you can use the following solution:

WebElement inputField = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//elementXpath")));
inputField.click();
inputField.clear();
inputField.sendKeys("name");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium