How to access elements when you get ElementNotInteractableException

My answer to this question on Quora:

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

ElementNotInteractableException is caused when an element is found, but you can not interact with it. For instance, you may not be able to click or send keys.

There could be several reasons for this:

  1. The element is not visible / not displayed
  2. The element is off screen
  3. The element is behind another element
  4. Some other action needs performed (by the user) to enable it.

Strategies that may work to make it interactable (depending on the circumstance.)

  1. Wait until an element is visible / clickable
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(ExpectedConditions.visibilityOf(element));
    wait.until(ExpectedConditions.elementToBeClickable(element));
  2. Scroll until the element is within view
    Actions action = new Actions(driver);
    action.moveToElement(element);
  3. Use javascript to interact directly with the DOM
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("document.querySelector('locator');
                      element.value = 'whatever';")
  4. Perform whatever other action is necessary and possibly wait until after that.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s