While using the WebdriverIO browser automation test framework based on the Webdriver protocol, I got stuck with this error: invalid element state: invalid element state
.
The error occurred when interacting with an input element. Since this error message is not very descriptive, I want to point to the solution for my situation.
To debug the issue, I found it very helpful to enable the WebdriverIO debug logs:
|
|
As you can clearly read from the logs, the test runner is able to find the element (#username
), then checks if the element is enabled, and finally tries to clear the element. This step fails with the mentioned error message.
The Webdriver standard includes this error with the following description:
A command could not be completed because the element is in an invalid state, e.g. attempting to clear an element that isn’t both editable and resettable.
The key is the word editable. When looking up the definition for editable, I could finally identify my issue:
Denotes input elements that are mutable (e.g. that are not read only or disabled) and whose type attribute is in one of the following states:
Text and Search, URL, Telephone, Email, Password, Date, Month, Week, TimeLocal, Date and Time, Number, Range, Color, File Upload
As it turns out, the selected input had type="hidden"
. This caused the test to fail, because you cannot set the value of a hidden input like this. Just then, I noticed that I matched for the wrong input element. As soon as I used the correct type="text"
input, the test worked flawlessly.