waiting for page to load

B

BobRoyAce

I have a website for which I am trying to automate interactions with.
The first page shows the first page of results of a search, each
result having a checkbox next to it.

In addition, I have code that performs two steps:
1) checks all checkboxes on the page, and
2) clicks on a link to go to the next page of results.

I also have code that uses a loop to perform these steps over and over
again, say 100 times. If I throw up an alert each time, before step
2, all works fine. However, if I don't, it doesn't work. The code for
the loop looks like follows:

for (var iPage = 1; iPage < 10; iPage++) {
checkAllCheckboxesOnPage();
clickNextPageLink();
}

checkAllCheckboxesOnPage works just fine, on it's own, as does
clickNextPageLink whidh looks like follows:

function clickNextPageLink() {
alert('Going to click on Next Page link!');
nextPageLink = document.getElementById("btnNextPage");
nextPageLink.click();
}

As long as I have that alert in there, it works. But, without it, it
doesn't. I'm assuming it's because the alert results in just enough of
a delay to let things work.

It should be noted that there is javascript on the page that runs in
the onclick event for each checkbox. An example follows:

<input name="dgSelect$ctl03" type="checkbox" id="dgSelect_ctl03"
onclick="javascript:pageMethods.UpdateSelectedRecords(this.checked,
'006303268', UpdateSelectedCount)" />

Lastly, just FYI, I am using Chickenfoot interface, in Firefox, to run
the script, by inserting a button on the page that runs my script.

Any ideas as to what I could change to make this work without an
alert?
 
M

Martin

As long as I have that alert in there, it works. But, without it, it
doesn't. I'm assuming it's because the alert results in just enough of
a delay to let things work.

how about setting a timeout for the function call of
clickNextPageLink() ?
(I hope I understood your problem ;-) )
 
D

david.karr

I have a website for which I am trying to automate interactions with.
The first page shows the first page of results of a search, each
result having a checkbox next to it.

In addition, I have code that performs two steps:
1) checks all checkboxes on the page, and
2) clicks on a link to go to the next page of results.

I also have code that uses a loop to perform these steps over and over
again, say 100 times. If I throw up an alert each time, before step
2, all works fine. However, if I don't, it doesn't work. The code for
the loop looks like follows:

for (var iPage = 1; iPage < 10; iPage++) {
checkAllCheckboxesOnPage();
clickNextPageLink();

}

checkAllCheckboxesOnPage works just fine, on it's own, as does
clickNextPageLink whidh looks like follows:

function clickNextPageLink() {
alert('Going to click on Next Page link!');
nextPageLink = document.getElementById("btnNextPage");
nextPageLink.click();

}

As long as I have that alert in there, it works. But, without it, it
doesn't. I'm assuming it's because the alert results in just enough of
a delay to let things work.

It should be noted that there is javascript on the page that runs in
the onclick event for each checkbox. An example follows:

<input name="dgSelect$ctl03" type="checkbox" id="dgSelect_ctl03"
onclick="javascript:pageMethods.UpdateSelectedRecords(this.checked,
'006303268', UpdateSelectedCount)" />

Lastly, just FYI, I am using Chickenfoot interface, in Firefox, to run
the script, by inserting a button on the page that runs my script.

Any ideas as to what I could change to make this work without an
alert?

In general, I would think that you have to make the iterations of the
loop event-driven, so the next iteration fires on completion of the
page update. using timeouts isn't good enough, that's just guessing.
You have to find an event that is automatically fired on completion of
the page update, or create your own custom event.
 
B

BobRoyAce

In general, I would think that you have to make the iterations of the
loop event-driven, so the next iteration fires on completion of the
page update. using timeouts isn't good enough, that's just guessing.
You have to find an event that is automatically fired on completion of
the page update, or create your own custom event.

Thanks for the input...will have to look into how to do stuff with
custom events...haven't done that kinda thing yet.
 
D

Dan Evans

How about using the onload event handler? You'd want to attach this
unobtrusively, in the ideal case but it would end up being this:

<script type="text/javascript">
function loadfunction(){
for (var iPage = 1; iPage < 10; iPage++) {
checkAllCheckboxesOnPage();
clickNextPageLink();
}
}
</script>
....
<body onload="loadfunction()">

I made a couple of assumptions, such as that iPage is available
globally. If it's not you will have to pass it in like
loadfunction(iPage). I assume that you had the for loop just sitting
in the script tag and so it would execute when the browser loaded that
script and if that script is in the <head> then that is before the
browser loads the body.

Moving your <script> to be the final child element of <body> should
have a similar effect but I recommend using onload="".

- Dan Evans
 
S

SAM

BobRoyAce a écrit :
I have a website for which I am trying to automate interactions with.
The first page shows the first page of results of a search, each
result having a checkbox next to it.

In addition, I have code that performs two steps:
1) checks all checkboxes on the page, and
2) clicks on a link to go to the next page of results.

I also have code that uses a loop to perform these steps over and over
again, say 100 times. If I throw up an alert each time, before step
2, all works fine. However, if I don't, it doesn't work. The code for
the loop looks like follows:

for (var iPage = 1; iPage < 10; iPage++) {
checkAllCheckboxesOnPage();
setTimeout('clickNextPageLink()',0);

}

or :

function checkAllCheckboxesOnPage() {
blah
blah
return true;
}

for (var iPage = 1; iPage < 10; iPage++) {
if (checkAllCheckboxesOnPage()) clickNextPageLink();
else alert('error #'+iPage);
}


not tested !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top