Forum Discussion

akash_pancholi's avatar
akash_pancholi
Occasional Contributor
14 years ago

WaitNamedChild fails to find object

I'm using this method to find mapped objects in an MFC application, in various cases, it fails to find the object even though it's there. Seems it's when parent object has WndClass #32770. For all popup windows, it consistently fails. There also are regular (non-popup) windows that have this class, where it is inconsistent. Using FindChild - depth 0, finds it all right, downside being, it is slower.



Is there any way to fix this? Or, a faster way to find child? 



Thanks.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The problem may not be in WaitNamedChild or FindChild but in a dynamic nature of the object being searched for.  It's possible, with the #32270 window, that there may be multiple instances with different captions, indices, etc.  Or they could be spawned from a different process than expected.  To better help figure this out, since you're using NameMapping (as evidenced by WaitNamedChild) it would be helpful to see a screenshot of the object being searched, the criteria being used in NameMapping to identify it, and perhaps the parent object itself.



    These are some directions to look in.



    As for a "better" way of using FindChild, it would be helpful to see the code in which you're using FindChild already.  FindChild allows you to pass in an array of properties and a corresponding array of values with a depth (how deep in the hierarchy to search).  So, there's any number of ways to "tweak" your use of FindChild by using different properties, different depth, wildcarding values, etc.  So, if you could post what you've used in FindChild already and perhaps a screenshot of the properties of the object you're trying to find, we might be able to help you find a good set of criteria to use for your search.
  • akash_pancholi's avatar
    akash_pancholi
    Occasional Contributor
    Hi Robert,



    Here's an example:



    I've 'Report' where Report is #32770 class.

    I use WaitNamedChild to get Print Button in 'Report' - mapped name - 'Print' - properties mapped with - objecttype = Button, objectidentifier = Print. There is only one child with these properties. (screenshot attached)



    validate after this call doesn't exist: validate = parent["WaitNamedChild"](name, 0); (where parent is Report object and name is "Print")



    As a workaround, I call FindChild, two properties, visible, mappedname, depth=0. Report can have anywhere from 20-70 children, so this is quite slow, but finds it all right. So far, I've seen this fail only when parent is class #32770, but not consistently.



    If I call WaitChild for this same object it finds it all right. Also, I called WaitNamedChild in TestComplete directly, exact same parameters, and it worked.



    I'm using connected application - C#, I tried the same in VB.net, just in case, but same result. It appears there is a problem only when using this with connected app. 



    Thanks.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I've 'Report' where Report is #32770 class.


    What other criteria do you use in your name mapping for this object?  Is the only thing you're using the #32770 class?  If so, then I'm not surprised as there are many other objects, items, etc., that may appear with that same class.



    Additionally, is this coming from a web page through Internet Explorer?  If so, what is the whole hierarchy of objects leading up to that object?  The reason being is that, starting with, I believe, Internet Explorer 7, IE can spawn multiple processes.  So, your original mapping MAY have been for process with an ID of 1, but subsequent runs of your tests may have the Report object coming up from other instances of IEXPLORE running in Windows.  There is a solution for this where you would need to adjust your registry.  I don't have the link immediately available but a search of these forums should find something about that.



     use WaitNamedChild to get Print Button in 'Report' - mapped name - 'Print' - properties mapped with - objecttype = Button, objectidentifier = Print. There is only one child with these properties. (screenshot attached)



    validate after this call doesn't exist: validate = parent["WaitNamedChild"](name, 0); (where parent is Report object and name is "Print")




    Where error shows up in your test log on this?  There's an additional information panel in your test log which may give additional information.  The problem may not be in the Report object or in your ability to find the Print object might might, as noted above, be further up in the hierarchy in that the instance of Internet Explorer that your original mapping references may not have your Report object on it but it may be on a different instance of IEXPLORE.



    I see your screen shot of the object in question, could you provide screenshots of your NameMapping hierarchy for the object (including the "tree" of objects from Sys up through the Report object), and the properties you're using for Mapping report?



    As a workaround, I call FindChild, two properties, visible, mappedname, depth=0. Report can have anywhere from 20-70 children, so this is quite slow, but finds it all right. So far, I've seen this fail only when parent is class #32770, but not consistently.




    I would not use MappedName in a FindChild call at all because MappedName is first of all depending upon the object being recognized as being mapped in NameMapping.  If you're already having trouble with WaitNamedChild, MappedName will almost certainly fail.  Again, I think the root cause of the problem is not with the Print button itself, but something in how you're mapping to the Report object is handled.



    Now, another possibility is that this call to find the print button is probably occurring after some sort of test step that generates the report in the first place.  So, there is probably a delay between clicking the button to generate the report and when the report appears on screen.  I would suggest going further up in your code and getting your actual Report object using a WaitChild or WaitNamedChild or something and using a delay parameter of something significantly greater than 0 (like 60000).  This will cause TestComplete to wait until the object resolves up to that timing before moving on.  A delay parameter of 0 basically says "don't wait" and you'll most likely fail pretty quickly if the object doesn't resolve equally quickly.



    Hope this helps you in finding what's going on.
  • akash_pancholi's avatar
    akash_pancholi
    Occasional Contributor
    ''What other criteria do you use in your name mapping for this object?  Is the only thing you're using the #32770 class?  If so, then I'm not surprised as there are many other objects, items, etc., that may appear with that same class.'' I use two - objecttype=dialog and wndclass=#32770, actually parent of 'Report' has only 1 child, so it doesn't actually matter. And, I check Exists and Visible property of 'Report' before searching its children. This is in MFC desktop application. 



    "Where error shows up in your test log on this?  There's an additional information panel in your test log which may give additional information" - log posts no error, do search operations not trigger logging? Is there any way to turn on the level of logging? By the way, I'm on version 7.52. 



    "I would not use MappedName in a FindChild call at all because MappedName is first of all depending upon the object being recognized as being mapped in NameMapping.  If you're already having trouble with WaitNamedChild, MappedName will almost certainly fail.  Again, I think the root cause of the problem is not with the Print button itself, but something in how you're mapping to the Report object is handled." - That's what I expected, but actually FindChild successfully finds it. 



    "Now, another possibility is that this call to find the print button is probably occurring after some sort of test step that generates the report in the first place.  So, there is probably a delay between clicking the button to generate the report and when the report appears on screen.  I would suggest going further up in your code and getting your actual Report object using a WaitChild or WaitNamedChild or something and using a delay parameter of something significantly greater than 0 (like 60000)" - This was my first guess, so after FindChild successfully found it, I called WaitNamedChild again, unfortunately, it still failed.  



    Also, as I mentioned in previous post, this actually works fine when in TestComplete script, it's only when I make the call via connected app, which suggests there is a bug with WaitNamedChild, possibly in how string parameter from connected app is handled. Attached please find screenshots of the hierarchy.

     

    Appreciate your input.



    Thanks,

    Akash
  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)

    Hello Aakash,


    I failed to reproduce the issue with the WaitNamedChild method you had described. Could you please consider sending our Support Team your application or a sample application along with the project suite demonstrating the problem? This will help us investigate your problem and find a solution faster.


    Thank you.