I am currently developing a test using Selenium and JavaScript.
During one part of the test, I need to go through an array of input elements and fill in values for those that are visible.
if (textInputs.length > 0) {
console.log('handling text input');
var i, textInputLen;
for (i = 0, textInputLen = textInputs.length; i < textInputLen; i++) {
(function (index) {
if (textInputs[index].isDisplayed()) {
textInputs[index].sendKeys("custom text box - " + textBoxes);
textBoxes++;
}
}(i))
}
}
However, I keep encountering the error message
ElementNotVisibleError: element not visible
when trying to fill in inputs that are not displayed on the DOM. What could be causing this issue? And how can I resolve it?
I have attempted different methods instead of using isDisplayed()
:
- I ran JS code to check if the element had visibility set to hidden or display set to none. The problem here is that the element being displayed could result from various reasons, so I am searching for a more universal solution. In this scenario, utilizing isDisplayed() would be ideal.
Please provide guidance on how to address this issue.