waiting for page to load

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BobRoyAce

    waiting for page to load

    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++) {
    checkAllCheckbo xesOnPage();
    clickNextPageLi nk();
    }

    checkAllCheckbo xesOnPage works just fine, on it's own, as does
    clickNextPageLi nk whidh looks like follows:

    function clickNextPageLi nk() {
    alert('Going to click on Next Page link!');
    nextPageLink = document.getEle mentById("btnNe xtPage");
    nextPageLink.cl ick();
    }

    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_ct l03"
    onclick="javasc ript:PageMethod s.UpdateSelecte dRecords(this.c hecked,
    '006303268', UpdateSelectedC ount)" />

    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?
  • Martin

    #2
    Re: waiting for page to load

    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
    clickNextPageLi nk() ?
    (I hope I understood your problem ;-) )

    Comment

    • david.karr

      #3
      Re: waiting for page to load

      On Jun 4, 9:29 am, BobRoyAce <b...@omegasoft wareinc.comwrot e:
      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++) {
      checkAllCheckbo xesOnPage();
      clickNextPageLi nk();
      >
      }
      >
      checkAllCheckbo xesOnPage works just fine, on it's own, as does
      clickNextPageLi nk whidh looks like follows:
      >
      function clickNextPageLi nk() {
      alert('Going to click on Next Page link!');
      nextPageLink = document.getEle mentById("btnNe xtPage");
      nextPageLink.cl ick();
      >
      }
      >
      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_ct l03"
      onclick="javasc ript:PageMethod s.UpdateSelecte dRecords(this.c hecked,
      '006303268', UpdateSelectedC ount)" />
      >
      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.

      Comment

      • BobRoyAce

        #4
        Re: waiting for page to load

        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.

        Comment

        • Dan Evans

          #5
          Re: waiting for page to load

          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++) {
          checkAllCheckbo xesOnPage();
          clickNextPageLi nk();
          }
          }
          </script>
          ....
          <body onload="loadfun ction()">

          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(iP age). 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 <headthen that is before the
          browser loads the body.

          Moving your <scriptto be the final child element of <bodyshould
          have a similar effect but I recommend using onload="".

          - Dan Evans

          Comment

          • SAM

            #6
            Re: waiting for page to load

            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++) {
            checkAllCheckbo xesOnPage();
            setTimeout('cli ckNextPageLink( )',0);
            }
            or :

            function checkAllCheckbo xesOnPage() {
            blah
            blah
            return true;
            }

            for (var iPage = 1; iPage < 10; iPage++) {
            if (checkAllCheckb oxesOnPage()) clickNextPageLi nk();
            else alert('error #'+iPage);
            }


            not tested !
            --
            sm

            Comment

            Working...