var result = []; var looper = function(data, srcVid, i) { result.push("\""+srcVid.src+"\""); if (i+1 >= data.length) { console.log(result.join("\n ")); return; } var y = data[i+1]; if (y) { y.click(); setTimeout(function(){ looper(data, srcVid, i+1); }, 1000); } } var x = document.getElementsByClassName("session-item-title"); var srcVid = $(".vjs-tech"); looper(x, srcVid, 0);