Forum Discussion

jose_pita's avatar
jose_pita
Super Contributor
12 years ago

10 seconds to find an object.

So, after having to redo all my tests because the developers changed all the structure of our webapp and all the name mapping objects were "Objects not found", I started to use the findChild function on the browser object.



A new problem arised, I put a timer everytime I used the function, usually it takes between 1 and 3 seconds to find the object, not too bad, but on some pages it takes 10 or more seconds...



The thing is, I can't give it a closer parent because it keeps changing. So, besides saving the father to a variable and keep updating it, what else can I do to avoid this situation? TC searches the entire structure before clicking the object, is it possible to make it click the first object it finds?



This is the DOM structure of the app (untitled.png).



This is the code i'm using:




startTimer();


   // Using the Find method 


   var parent= Sys.Browser("iexplore").Page("*");


   var celula;


  


  var pro_name = new Array(propertyName,"VisibleOnScreen");


  var pro_value = new Array(propertyValue,"True");


 


if(tab.Exists)


{


    celula = parent.FindChild(pro_name ,pro_value ,20);

    celula.Click();

}

stopTimer();

  • Hi Jose,



    The best way to decrease that time is using a closer parent, of course. But even if it keeps changing, there's no problem at all, TC will update the object DOM (and if not, you can force it to).



    So, even if the object contents change, while you can retrieve it there's no problem at all.



    Also, you can try changing the search depth. If you know what depth will always have (I assume there is no way an object moves from depth 5 to 12, for example), set this depth + 1 as search depth, just to make sure:



    celula = parent.FindChild(pro_name ,pro_value ,expected_depth + 1);

    celula.Click();



    You can check my blog, I've written a bit about it.



    Hope it helped!
  • Hi Jose,



    The best way to decrease that time is using a closer parent, of course. But even if it keeps changing, there's no problem at all, TC will update the object DOM (and if not, you can force it to).



    So, even if the object contents change, while you can retrieve it there's no problem at all.



    Also, you can try changing the search depth. If you know what depth will always have (I assume there is no way an object moves from depth 5 to 12, for example), set this depth + 1 as search depth, just to make sure:



    celula = parent.FindChild(pro_name ,pro_value ,expected_depth + 1);

    celula.Click();



    You can check my blog, I've written a bit about it.



    Hope it helped!
  • jose_pita's avatar
    jose_pita
    Super Contributor
    Yes, i know all about that Javier, the problem is, I have more than 100 different pages mapped and they may or may not all have the same structure, if it changes I have to go and manually change all of them on the name mapping...



    Now I'm using scripts and in the path to the parent I'm using the real path (Sys.Browser("iexplore").Page("*")....) that is easily changed by using the replace functionality, I was just wondering if someone had a better way of doing this...



    Thanks anyway.
  • I was talking about scripting too. The point is that you don't have to use the page object to perform all the searches.



    For example, if you know that there will be always a iframe with the same ID, you can search beneath that object, not under the page object.



    On the other hand, if all the DOM may change during sprints... I'm so, so, so sorry. I've written about it on my blog too. Please check it to see if my solution helps you, but I'm afraid that a complete restructuration of a web page will mean an automation refactoring.



    Good luck!