[Troubleshooting 101] Invalid element state exception using setText

Troubleshooting: InvalidElementStateException when using setText

Problem

You may encounter the following exception during web test execution:

org.openqa.selenium.InvalidElementStateException:
invalid element state: Element is not currently interactable and may not be manipulated

This usually happens when Selenium/Katalon tries to interact with an element that exists in the DOM but is not ready for interaction.

Common Causes

  • The element is not visible yet
  • The element is disabled or covered by another element
  • The page is still loading or updated dynamically (AJAX)
  • The element requires a different interaction approach

Solution 1: Wait Until the Element Is Visible

Before interacting with the element, make sure it is visible and ready.

WebUI.waitForElementVisible(findTestObject(‘your/object’), 30)
WebUI.setText(findTestObject(‘your/object’), ‘Your Value’)

Solution 2: Set the Value Directly Using JavaScript

If the element is visible but still not interactable (for example, due to custom UI controls), you can set the value using JavaScript.

import com.kms.katalon.core.webui.common.WebUiCommonHelper
import org.openqa.selenium.WebElement
import java.util.Arrays

WebElement element = WebUiCommonHelper.findWebElement(
findTestObject(‘your/object’), 30
)

WebUI.executeJavaScript(
“arguments[0].value=‘Your Value’”,
Arrays.asList(element)
)

This approach bypasses standard Selenium actions and directly updates the element.

→ This exception is usually caused by timing or visibility issues. Waiting for the element or using JavaScript when needed can help resolve it effectively.

3 Likes

Another good article for beginners on InvalidElementStateException

2 Likes

Nice piece of information

4 Likes

for anyone who’s still running into this, here’s a quick checklist i usually go through when i see InvalidElementStateException:

  • make sure the element is visible and enabled (not readonly / disabled, and not covered by an overlay)
  • add an explicit wait like waitForElementClickable() before calling setText()
  • try clearText() first, or use sendKeys() if setText() keeps failing
  • for readonly or custom inputs, setting the value via JavaScript can be more reliable
  • double check the context (iframe, window, or shadow DOM) and switch to it if needed
3 Likes