ElementNotInteractableException on a span object

Skip to first unread message

Sir Jo

Dec 29, 2022, 10:02:39 PM12/29/22
to Selenium Users
when I try to use this code:
span = el.FindElement(By.CssSelector("span[data-testid='StampaAvvisoPagamento']"))
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  ????


Jan 4, 2023, 6:59:15 PMJan 4
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.


Hamim Alam

Jan 15, 2023, 11:17:37 PMJan 15
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. 

public static void waitTillDisplayed(WebDriver driver,String by, Integer timeout) {
        Integer dTime1 = timeout;
        if (timeout == null) {
            dTime1 = 5000;
        WebDriverWait wait = new WebDriverWait(driver, dTime1);


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

Hope this helps :)

Reply all
Reply to author
0 new messages