How do I resolve the ElementNotInteractableException in Selenium WebDriver

0 votes
How do I resolve the ElementNotInteractableException in Selenium WebDriver?
Aug 21, 2019 in Selenium by Abish
106,261 views

3 answers to this question.

+1 vote

Hi Abish, ElementNotInteractableException occurs when an element is found, but you can't be interacted with. For instance, you may not be able to click or send keys. This could happen due to various reasons like element being not visible or displayed, element is off screen or element is behind another element or hidden. So, you can perform some of the actions to make element interactable:

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 the the display

Actions action = new Actions(driver);
action.moveToElement(element);

3. Use JS Executor to interact directly with the DOM

JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("var element = document.querySelector('locator'); element.value = 'whatever';")

You can refer to the Selenium Testing Course for further understanding.

answered Aug 21, 2019 by Abha
• 28,140 points

edited Aug 4, 2023 by Khan Sarfaraz
There where 03 possible solutions for it:

1. When page is rendering at that time selenium trying to click. Solution is add explicit wait
2. If developer has developed website in a such way like element is not interact then find it's parent element and using xpath child function you can implement it. Example: //div[contains(@class = 'abc')]::*

3. Find element's coordinate and try to click on element using coordinate
Hi Shreyans, thank you for your answer. You explained it really well.
3rd point can u explain detailed.
Hey, did you mean @Abha's answer or @shreyan's answer?
HI,

I tried this way of 3 steps but getting issue that cannot set property value of null

Hello,

Which 3 steps are you talking about? @ Abha solution or @Shreyans shah? and  share more information about your problem

0 votes

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 or hidden
  4. Some other action needs to be performed by the user first 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 the the display

    
    
    
    • Actions action = new Actions(driver); 
    • action.moveToElement(element); 

      3. Use javascript to interact directly with the DOM

      
      
      
      • JavascriptExecutor javascript = (JavascriptExecutor) driver; 
      • javascript.executeScript("var element = document.querySelector('locator'); element.value = 'whatever';") 

        4. Perform whatever other action is necessary and possibly wait until after that.

        answered Dec 14, 2020 by Roshni
        • 10,520 points
        0 votes

        ElementNotInteractableException

        ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the HTML DOM, it is not in a state that can be interacted with.

        Reasons & Solutions :

        The reason for ElementNotInteractableException to occur can be numerous.

        1. Temporary Overlay of other WebElement over the WebElement of our interest :

          In this case, the direct solution would have been to induce ExplicitWait i.e. WebDriverWait in combination with ExpectedCondition as invisibilityOfElementLocated as folllows:

          WebDriverWait wait2 = new WebDriverWait(driver, 10);
          wait2.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("xpath_of_element_to_be_invisible")));
          driver.findElement(By.xpath("xpath_element_to_be_clicked")).click();
          

          A better solution will be to get a bit more granular and instead of using ExpectedCondition as invisibilityOfElementLocated we can use ExpectedCondition as elementToBeClickable as follows:

          WebDriverWait wait1 = new WebDriverWait(driver, 10);
          WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
          element1.click();
          
        2. Permanent Overlay of other WebElement over the WebElement of our interest :

          If the overlay is a permanent one in this case we have to cast the WebDriver instance as JavascriptExecutor and perform the click operation as follows:

          WebElement ele = driver.findElement(By.xpath("element_xpath"));
          JavascriptExecutor executor = (JavascriptExecutor)driver;
          executor.executeScript("arguments[0].click();", ele);

        answered Dec 14, 2020 by Gitika
        • 65,890 points

        Related Questions In Selenium

        0 votes
        1 answer

        How do i change the location where my file gets downloaded in Selenium Webdriver and firefox driver?

        There are a couple of errors there. ...READ MORE

        answered Apr 13, 2018 in Selenium by nsv999
        • 5,500 points
        6,126 views
        0 votes
        1 answer

        How do I get current URL in Selenium Webdriver using Python?

        Use current_url element. Example: print browser.current_url READ MORE

        answered Aug 8, 2018 in Selenium by Meci Matt
        • 9,460 points
        25,889 views
        0 votes
        1 answer
        0 votes
        1 answer

        How do I increase or decrease the sleep time in clickAndWait command in selenium IDE?

        If you are using Selenium Webdriver, you have ...READ MORE

        answered Feb 28, 2019 in Selenium by Vaishnavi
        • 1,180 points
        2,369 views
        0 votes
        2 answers

        Finding WebDriver element with Class Name in java

        The better way to handle this element ...READ MORE

        answered Apr 10, 2018 in Selenium by nsv999
        • 5,500 points
        13,429 views
        0 votes
        2 answers

        Problem while using InternetExplorerDriver in Selenium WebDriver

        enable trusted connection  in internet explorer by ...READ MORE

        answered Aug 31, 2020 in Selenium by Sri
        • 3,190 points
        9,004 views
        0 votes
        1 answer

        Geo-location microphone camera pop up

        To Allow or Block the notification, access using Selenium and you have to ...READ MORE

        answered May 11, 2018 in Selenium by Samarpit
        • 5,910 points
        7,113 views
        0 votes
        2 answers

        How to use such xpath to find web elements

        xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

        answered Sep 3, 2020 in Selenium by Sri
        • 3,190 points
        7,804 views
        +1 vote
        1 answer

        how do I escape the "/" in a textarea for Python3.7 with Selenium

        @tchrisev, try using Robot class with following commands after your send_keys() ...READ MORE

        answered Oct 29, 2019 in Selenium by Abha
        • 28,140 points
        1,464 views
        +1 vote
        1 answer
        webinar REGISTER FOR FREE WEBINAR X
        REGISTER NOW
        webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP