In my Chrome extension, I have an array of anchor tags (from the DOM) which are the links of downloadable files and I'm clicking on them in the loop using .click()
, but only the last link is clicked. I used setTimeout
, but it's clicking only the last element.
I checked my console; even with setTimeOut
it prints the values all together at once.
setTimeout(() => {
let rows = document.getElementsByClassName('jz-table is-bordered-horizontal')[1].rows
for (let i = 1; i < rows.length; i++) {
setTimeout(() => {
console.log(i)
if (typeof rows[i].querySelectorAll("a[ng-switch-when=Download]")[0] != "undefined") {
console.log(rows[i].querySelectorAll("a[ng-switch-when=Download]")[0])
rows[i].querySelectorAll("a[ng-switch-when=Download]")[0].click()
}
}, 2000);
}
}, 2000);