Link to home
Start Free TrialLog in
Avatar of Jim
JimFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Element Not Interactable - Selenium VBA

Hi all - thanks for reading:

I am trying to use the below to populate a text box using VBA and Chromedriver/Selenium:

ch.FindElementById("signInFormUsername").SendKeys "TEST"

Open in new window

but I get a

"Run-time error '0' - element not interactable"

However, oddly if I open the 'inspect element box' the code does run.

When the inspect element box is not open the following is false:

ch.FindElementById("signInFormUsername").IsDisplayed

Open in new window

So some how the 'inspect element box' displays the element.

Is this perhaps a road to a solution? Is there a way to code the display of the element?

Thank you in advance for any help.

Avatar of Bembi
Bembi
Flag of Germany image

Hello,
just a thought as this happens often in office vba...
If you request properties from an object, the object has to be inside the scope the code is running.
There are several reasons, why the access to the object fails....
a.)  the object is not accessible, because the focus is somewhere else (i.e not active, not visible).
You have to make sure, that an object is visible and (possibly) has the focus during runtime. 
b.)  the object is not accessible, because it doesn't exist (not opened, already closed etc.)
c.) be aware of timing problems.
If you step through the code or use an immediately window, code may function because you are currently in the correct context (maybe by activating the object with the mouse or due to the logic, how the code is processed).
The behaviour during runtime can be different. In VBA it is a common issue that sub procedures are called while the calling code can continue while calling functions force the calling code to wait for the result.
In debug mode, each sub procedure behaves like a function, in runtime mode it does not.

A common way to avoid such timing issues is to define subprocedures as function rather than subs duie to this behaviour (a common issue in excel vba, where under runtime conditions subsequent advices in the calling procedure changes the focus while a sub procedure relys on it).  
Avatar of Jim

ASKER

Thanks Bembi for you comment.

I found the solution:

I was referencing what I thought was an unique id. But in fact there were two elements with the same id and I was originally referencing the id that was hidden (hence the error). I therefore changed the reference to the other id which was not hidden and it worked.
ASKER CERTIFIED SOLUTION
Avatar of Jim
Jim
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial