In my previous asked question, I had some problem with delaying. Previous question: delay with settimeout and for loop
My purpose is get some datas from a website, and I use console in IE. The content is changed when the user clicks on an element which has tagname "something"
This code runs perfectly if i want only to clicking on the elements through:
for (var x = 1; x < 5; x++) {
(function(i) {
setTimeout(function() {
document.getElementsByTagName("something")[i].click(); }, i * 1000)
}(x))
}
But in my casy i need also get the content from the site after clicking, so I added a new line after clicking:
myarray=[];
for (var x = 1; x < 5; x++) {
(function(i) {
setTimeout(function() {
document.getElementsByTagName("something")[i].click();
var x=theelement.innerHTML;
myarray.push(x);
}, i * 1000)
}(x))
}
So with an array I can get the contents after clicking. The problem is that after the clicking the site loads ~1-2 seconds and my above code tries immediately get the element and assign its innerHTML value to the x variable.
I tried to making a "nested delay" inside the delay but not works, because they evaluate separetly. So I tried to solve like this the problem:
outer settime with delay 1000ms
element.click()
inner settime with delay 3000ms
x=element.innerhtml
innersettime close tag
outer settime close tag
In this case the inner settime and the outer settime evaluates separatly and not like a well-known sleep() functions like in other languages. The purpose is making delay between "clicking" and "get the content of an element" functions. And this 2 functions must be repeated 30 times. And between these 30 times also must be delay.
link1.click();
3sec pause; -->this is the pause between "click" and "get content"
x=elem1.innerHTML;
myarray.push(x);
1sec pause;
link2.click();
3secpause; --> this is the pause between each loop (there is 30link on the site)
x=elem2.innerHTML;
myarray.push(x);
until link30.click()....
The url doesnt change, only the content.