How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?

前端 未结 5 1342
春和景丽
春和景丽 2020-11-21 13:53

Here I have the image of my code and the image of my error. Can anyone help me to resolve this issue?

相关标签:
5条回答
  • 2020-11-21 14:13

    Actually the Exception is Element Not Visible

    The best practice is to use Implicit wait below driver Instantiation so it get sufficient time to find element throughout the exception

    driver.get("http://www.testsite.com");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
    

    Still facing issue as some element require more time. Use ExplicitWait for individual element to satisfy certain condition

    In your case you are facing element not visible exception then use wait condition in following way-

    WebDriverWait wait = new WebDriverWait(driver, 120);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.your_Elemetnt));
    
    0 讨论(0)
  • 2020-11-21 14:19

    A solution to this for Javascript looks like this. You will have to modify the time to suit your need.

    driver.manage().setTimeouts({ implicit: 30000 });

    Hope this is helpful to someone. see the docs for reference

    0 讨论(0)
  • 2020-11-21 14:20

    I got this because the element I wanted to interact with was covered by another element. In my case it was an opaque overlay to make everything r/o.

    When trying to click an element UNDER another element we usualy get "... other Element would receive the click " but not always :.(

    0 讨论(0)
  • 2020-11-21 14:21

    This Exception we get when the element is not in an interactable state. So we can use wait till the element is Located or become clickable.

    1. Try using the Implicit wait:

      driver.manage().timeouts().implicitlyWait(Time, TimeUnit.SECONDS);
      
    2. If this is not working use Explicit wait:

      WebDriverWait wait=new WebDriverWait(driver, 20);
      WebElement input_userName;
      input_userName = wait.until(ExpectedConditions.elementToBeClickable(By.tagName("input")));
      input_userName.sendkeys("suryap");
      

    You can use ExpectedCondition.visibilityOfElementLocated() as well. You can increase the time, for example,

    WebDriverWait wait=new WebDriverWait(driver, 90);
    
    0 讨论(0)
  • 2020-11-21 14:27

    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);
      
    0 讨论(0)
提交回复
热议问题