Forum Discussion

thexder1's avatar
thexder1
Contributor
12 years ago

find object

I am working with software that has objects in the UI that have Items and sub Items, I am trying to find a way to check and see if an Item already exists, I need to be able to search through the entire hierarchy for it which could be 5 levels deep. I thought that the find object method would work for this, but when I put it in the test it asks for a property and a value and no matter what I enter in there it always says that it cannot find it. I have always worked with that with the correct window open and the Items already existing in the object. 



Is there something that I am missing? Is there a better way to do this? So far the best that I have been able to come up with is to try selecting the item, calling the object method wSelected to get the currently selected item, then use an if then to check what is selected. The problem with this method of checking is that if the item does not exist then I get an error in the test eventhough it is not really a failure.



So far I am only working with keyword tests, but I am not opposed to changing the tests to a script, I just have not had to yet so I have not done it.

10 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Can you post a screenshot or something of your Find test that you are using?  This might be helpful in debugging what the potential problem would be.
  • I would but I cannot even save the find object because I always get the error message No child object of <long name pointing to selected object> was found using the following properties:



    It does not matter what I enter for the property or the value, It also does not seem to matter what object I select I always get the same message. I have tried entering multiple property names as they appear in the property list when using object spy to look at them.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Do you have the object open and visible on screen when you're trying to make those edits? Using Keyword Tests, when adding the "Find Object" method, it looks at the actual system environment to validate what you are entering.





  • Yes I do have it open and visible. I am trying to find an object that is curretly displayed. Please note that my goal is to find a specific Item within an object. The object that I am pointing to is a tree view with a list of items and subitems and I need to check and see if an item already exists within the tree without throwing an error in the log like I currently have it doing.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It is possible that the particular component you are working with (the tree view) does not support an "open" architecture with TestComplete.



    If you use the Object Spy built into test complete, can you see the individual items on the tree view?  It is possible that they are not seperate objects as seen by test complete but values within a property list or some other non OLE compatible object.





  • They appear as the Items property, The fact that they are not seen as objects is the reason I have had problems getting things like this to work. Is there some way to search through a nested set of properties for a specific sub property, or a specific set of sub properties? Since that is what it looks like I need to do.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    If they are the Items property, than they can be referenced, I believe, as an indexed array.



    You might need to write a for loop of sorts to loop through the list of items from 0 to max item count (whatever the property name is) and check to see if the item a) exists and b) is selected.

  • The way that I am doing it right now is much easier than that because I do not need a series of nested for loops to check all possibilities, but the problem is that it puts an error in the log for the test if I try to reference an item that does not exists, or with the method that I am currently using if testcomplete tries to select an Item that does not exist. I am trying to avoid false errors like that.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The only way to avoid false errors is to search for the object using a method that does not try to declare the object without first looking for it's existance.  I think you're going to have to use an iterative loop.  If done correctly, you can create it as a function in a script unit that can be called at any time to "find" any given item within your tree view.
  • Thanks, I was afraid that was what it would be, I have not found a way to do that yet, but I will check again to see if I can come up with something that will work without giving an error.