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: Waiting for ActiveX object to have initialized - comp.lang ...You can do a document.write there if it is done while the page is loading. ... Waiting for ActiveX object to have initialized - comp.lang ... Using ActiveX ... Pdf javascript event onOpen, OnLoad? - comp.text.pdfIn summary, I am using a onLoad event in the BODY tag to ... comp.lang.javascript 30938 articles. 9 followers. ... Could Not Load the Index - Help - comp.text.pdf Help ... help on progressbar - comp.lang.perl.tkHelp with status bar - still showing load in progress even after ... help on progressbar - comp.lang.perl.tk Help with status bar - still showing load in progress even ... Help with status bar - still showing load in progress even after ...Hi, I'm having an issue with the status bar in Mozilla and Netscape showing that it is still waiting on the page to load even after it is finished. ... show a wait box - comp.lang.javascriptare there a solution to show a little div while the page is loading and then make it to ... Lock ASP.NET Page and Show Animated Image While Waiting for a Long ... Let’s ... ServerSocket.accept() stops GUI loading - comp.lang.java.gui ...ServerSocket.accept() stops GUI loading - comp.lang.java.gui ... Hi, I am trying to ... How to stop a thread which is waiting for a client socket connection? How to stop a ... Average wait time per IO request and ... - comp.unix.solaris ...... wait time per IO request", "total time spent waiting for ... information in Solaris, take a look at the man page for ... CPU idle time was 1% or 2% for all the CPUs but load ... Control external software with Matlab - comp.soft-sys.matlab ...I wish to open a commercial software, load a file, set ... Benítez looking at the software download page of ... I wrote to Polar support, I'm waiting for an answer. Accessing the UART for serial communication in linux - comp.unix ...I am not able to recompile my kernel without >the module support disabled and thats why i am not able to load my >module. > >waiting for ur earliest reply Wellll... Disable the God forsaken Firefox Adobe Acrobat PDF plugin (please ...Like many people, I can't stand waiting a tremendously long time for a PDF file to ... even after waiting interminably for the dastardly Adobe Acrobat PDF plugin to load ... Waiting, Waiting, Waiting for My Page to Load - Stacey MyersThis is not great news when page load speed is one of the things that Google looks at when ranking your page. With further investigation, although this is true, it ... waiting for page to load - Application Forum at ObjectMix.comI 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 7/30/2012 1:32:21 AM
|