waiting for page to load

  • Follow


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?
0
Reply BobRoyAce 6/4/2008 4:29:22 PM

> 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 ;-)  )
0
Reply Martin 6/4/2008 9:06:46 PM


On Jun 4, 9:29 am, BobRoyAce <b...@omegasoftwareinc.com> wrote:
> 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.
0
Reply david 6/4/2008 9:53:03 PM

> 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.
0
Reply BobRoyAce 6/5/2008 2:26:35 AM

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
0
Reply Dan 6/5/2008 4:56:23 PM

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 !
-- 
sm
0
Reply SAM 6/5/2008 6:42:19 PM

5 Replies
172 Views

(page loaded in 2.662 seconds)

Similiar Articles:













7/30/2012 1:32:21 AM


Reply: