Trying to figure out how to click a button multiple times based on the number of elements found with a specific classname. If there are 3 elements found, the button should be clicked 3 times.
The current approach:
(Update at the bottom)
The total count of btn btn-remove btn-outlined
elements in the HTML can vary, so I tried to read this count first and then loop through that many times to click the button accordingly.
The issue I'm facing is that although it correctly identifies the number of elements (e.g., 3), the loop seems to be skipping the necessary it functions inside for some unknown reason.
Here's where it goes wrong:
it('Click remove button - ' + i + '/' + text.length, function (done) {
browser.driver
.then(() => browser.executeScript("arguments[0].click();", element.all(by.className('btn btn-remove btn-outlined').first().getWebElement())));
.then(() => done());
});
it('Wait for fading button to be gone', function (done) {
setTimeout(function () {
done();
}, 1000);
});
I suspect there might be an error that I'm overlooking. How do I determine the number of specified elements in the DOM and iterate through them while clicking on the remove button?
EDITED CODE:
it('Click remove button', function (done) {
element.all(by.className('btn btn-remove btn-outlined')).getText().then(function (text) {
console.log(text.length) //returns 3
for (var i = 0; i < 4; i++) {
console.log(i); //Prints 0, 1, 2
it('Click remove button - ' + i + '/' + text.length, function (done) {
console.log("Remove button"); //Doesn't print
browser.driver
.then(() => browser.executeScript("arguments[0].click();", element.all(by.className('btn btn-remove btn-outlined').first().getWebElement())));
.then(() => done());
});
it('Wait for fading button to be gone', function (done) {
console.log("Timeout"); //Doesn't print
setTimeout(function () {
done();
}, 1000);
});
}
})
done();
});