ElementNotInteractableException on a span object

66 views
Skip to first unread message

Sir Jo

unread,
Dec 29, 2022, 10:02:39 PM12/29/22
to Selenium Users
Hello,
when I try to use this code:
span = el.FindElement(By.CssSelector("span[data-testid='StampaAvvisoPagamento']"))
span.Click()
there is the error: OpenQA.Selenium.ElementNotInteractableException

But if I use this code:
span = el.FindElement(By.CssSelector("span[data-testid='StampaAvvisoPagamento']"))
driver.ExecuteScript("arguments[0].click();", span)
It works !!!

is or isn't interactable ??

.....why  ????




Adrian

unread,
Jan 4, 2023, 6:59:15 PM1/4/23
to Selenium Users
I don't know, but I am going to take a guess.

The ExecuteScript function is fast - very fast!  This is because I believe it runs directly in browser and I don't think it waits for the page have completed loading.
Where as the FindElement function has to go thru a few steps before running in the browser and it waits for the page to load fully.

I am thinking that your web page is being generated and then widgets on the page are being refreshed to show a new status.  
In-between the page being generated and the widgets being updated I think the ExecuteScript is running and it can successfully click on the element.
FindElement is a little slower, so I think it is running after the page has completed loading and at that point the element you are targeting is not interactable.


Cheers,
Adrian.

Hamim Alam

unread,
Jan 15, 2023, 11:17:37 PM1/15/23
to Selenium Users
There is nothing wrong with the code. What I can see is, the execution of the code is fast!!!! 
You can create a function that makes sure the element in visible or displayed or enabled. 

ex:
```
public static void waitTillDisplayed(WebDriver driver,String by, Integer timeout) {
        Integer dTime1 = timeout;
        if (timeout == null) {
            dTime1 = 5000;
        }
       
        WebDriverWait wait = new WebDriverWait(driver, dTime1);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(by)));
    }

```

You can use above function to make sure the element is displayed and perform action....

Hope this helps :)

Reply all
Reply to author
Forward
0 new messages