Forum Discussion

paul_grizzaffi's avatar
paul_grizzaffi
Occasional Contributor
11 years ago

Wait time for FindAll

Hi,

I want to change the time that the FindAll method waits for an HTML element to exist, but I can't seem to find the info.



Is it possible to do this? If so, how? Or please point me to the correct documentation.



Thanks!

Paul

8 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    There may be another way to do this but I added a function with the FindAll to call it's self back.

    Ex:




    function find(fullname){


    var start = new Date().getTime();

    //searching within page object

    Sys.Browser('iexplore').Refresh();



    var m = (new VBArray(Sys.Browser('iexplore').Page('*').Find('FullName',fullname,20000,true))).toArray();


    if (m){



     return m;


     }


    //continue to timeout


    t += (((new Date().getTime() - start) / 1000));


    if (t >= 60){ //60 second time out


     Log.Error('Unable to find object.',fullname);


     return undefined;


     }


    else{


     aqUtils.Delay(1000,'Searching for object...');


     return find(fullname);


     }


    }



  • paul_grizzaffi's avatar
    paul_grizzaffi
    Occasional Contributor
    Ryan,

    Thanks for the quick reply. My approach for waiting is similar to yours, just non-recursive.



    More specifically, what I'm asking is this: how do I reduce the time that the find FindAll waits for an element to exist? In the one example I'm looking at, FindAll seems to wait about 9 seconds for the element to appear, I would like to reduce that amount of time so that I can "poll" more frequently.



    Hopefully someone can help with this.



    Thanks again,

    Paul
  • chrisb's avatar
    chrisb
    Regular Contributor
    Put your search in a loop and avoid hard coded delays where possible.



    As a suggestion I am using the Find method in a function that locates objects for me on a web page. I have this inside a loop that quits after n number of times and returns the object if it is found so I can perform whatever operations I like on it, ie. Click, Add Text, etc.



    A little bit of testing showed me that quitting after 10 tries was sufficient in our app to know with confidence if the object was found or not. 



    Set Obj = sys.Browser("iexplore").page("*").Find(PName,PValue,20000,TRUE)



    The time to find the objects using the above method is determined by the time it takes for the FindAll methods to traverse the tree and return all the found objects. 



    Further, If you are testing a web application in IE you can use CurrentPage.Wait method for the page to load and place it before your FindAll, no loop required then as the search is only done one time once the page has loaded. 




    Do


     


     Set Obj = sys.Browser("iexplore").page("*").Find(PName,PValue,20000,TRUE)

     i = i+1


     


     Loop Until Obj.Exists or i=10




    'return object if found 

     


     If Obj.Exists Then


      Set LocateObject = Obj

      Exit Function

     



     Else

     


      log.error("LocateObject: object with Property Value: ")&PValue &(" wasn't found")



     End IF




     
  • paul_grizzaffi's avatar
    paul_grizzaffi
    Occasional Contributor
    Chris,

    Thanks for the info. Two things...


    1. Based on what you said, my FindAll is taking 9 seconds due to the length of time it takes to traverse the whole DOM. Correct? If so, interesting; I hadn't thought of that and I'll have to give it a try.


    2. Regarding the Wait, I've seen a couple of instances using IE where the Wait returns indicating the page is no longer busy, but the page is still not loaded. I discovered this when chasing down a race condition. Verified this by recording a screen video of the execution and stepping through the replay of the video frame-by-frame; doing this, I discovered that the page busy "spinner" in the IE tab was still visible, but script execution had continued.


    Thanks again,

    Paul



  • chrisb's avatar
    chrisb
    Regular Contributor
    Hey Paul,



    1. Nope, I am saying it sounds like you look for the object, wait for a set amount of time the look for object again. I am suggesting removing the delay if you have one and simply putting the search inside a loop to keep traversing the tree continuously.



    2. See below.





    Post a code snippet of how you are doing your FindAll and waiting for page to load, then we can see how your are doing it and maybe why it is taking 9 seconds.



    9 seconds does sound excessive assuming your page is not loading slowly or there is an awful lot of objects to find and or a large tree. 



    Take a look at the documentation for the Wait method, I believe there are some caveats around using that such as not  being supported in some browsers and if I remember correctly there are also some tips on waiting for page loads there too. 



  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    " I would like to reduce that amount of time so that I can "poll" more frequently"



    The 9 seconds you are seeing is "probably" the Find/FindAll method refreshing the object tree. You can set this to false but it may cause other issues.




    Sys.Browser('iexplore').Page('*').FindAll('FullName',fullname,20000,false)