Forum Discussion

petra's avatar
petra
Contributor
8 years ago

Finding Objects Delphi

Hi there.

 

Sometimes Test complete can't find the right object.

 

The correct name of the object (marked in red in attachment) is DBText12.

 

Every x-th time TC says "No the name isn't DBText ...... The name is shape1"

 

On these times TC also couldn't "see" buttons, but only the Panel behind

 

Do anyone have an idea how to handle.

 

pe:

 

Cancelling this teststep is no idea if you click on the object, a window appears.

 

Searching for DBText OR shape is no good idea too.

 

Please help!

 

 

 

 

  • Need more info.

     

    Is this a mapped object? What properties are you using to map it? Because it sounds like it's finding the wrong object sometimes, which suggests your mapping is not strong enough.

     

    And what are you trying to do at the point it finds the wrong object? Is this during a run? Sounds like you don't get an error message, more that the test doesn't work as it finds and uses the wrong object.

     

    But need more details to have any chance of working out what's going on ....

    • petra's avatar
      petra
      Contributor

      Errorwarning is

       

      An error occurred while accessing the "Click" method or property of the "DBText12" object.
      The object or one of its parent objects was not found.

      Object Whose Method or Property Was Accessed

      Alias:Aliases.Kasse.ArtBei.DBText12
      Name mapping item:NameMapping.Sys.Kasse.ArtBei.DBText12

      Object That Was Not Found

      Alias:Aliases.Kasse.ArtBei.DBText12
      Name mapping item:NameMapping.Sys.Kasse.ArtBei.DBText12

       

       

      Mapped with TDBText (ClassName)

      DBText* (Native DelphiObject.Name)

       

       

       

      I try to make a klick in this window named DBText12. Then another window appears.

       

       

       

      Test:

       

       


      DBText12 Click ... Clicks at point (73, 9) of the 'DBText12' object.

       

      (a window appears if dbText12 is found -- on this window)


      BitBtnCancel Click ... Clicks at point (74, 27) of the 'BitBtnCancel' object.

       

       

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        OK.

         

        Sounds like either a sync issue - so the object is not yet ready at the point you're trying to use it. In which case, you should put some sort of checking step in before you try and use it.

         

        Or ....

         

        Your mapping is not tight enough and it's failing to identify something at runtime. If this is the case, it could be anything in the object tree for "NameMapping.Sys.Kasse.ArtBei.DBText12". If any of the components are not available, it will fail as you're describing as the object at the end of the tree can't be found. One bad link breaks the chain.

         

        I have no idea what "shape1" that you mention in your original post has to do with any of this? What you're describing sound like a standard "object not found" type problem.

  • m_essaid's avatar
    m_essaid
    Valued Contributor

    Hi petra,

     

    if it's a timeout issue and you're waiting for an object to appear, you'll need to implement this function (that is in SmartBear's sample files)

     

    function WaitAliasChildFunction(object: AliasObj; Name: string, time: integer):Boolean;
    var AliasObj;
    begin
    // Specifies the Alias object
    AliasObj := object;
    // Checks whether the Font window has appeared within 10 seconds
    if (AliasObj.WaitAliasChild(Name, time).Exists) then
    begin
    Result:= true;
    Log.Message('Element found : ' + Name)
    end else
    begin
    Result:= False;
    Log.Message('Elément not found : ' + Name);
    end;
    end;

     

    ----------------------

     

    if you want to use this short script you write :

     

    if (WaitAliasChildFunction(Aliases.Kasse.ArtBei, 'DBText12', 15000)) then

      ... etc

     

    ----------------------

     

    in this script, you could put everything as a child. and you won't need to wait for 15 seconds (in this example) : when the DB will be in memory, the counter will stop and it will do the "then" block

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      m_essaid

       

      That will not work 100% of the time.

       

      It depends how your developers are removing or hiding objects.

       

      My application is Delphi. Some objects, when they are not in use, are hidden. Some are destroyed. So I can't rely solely on exists. It's not enough. I have to check Exists, VisibleOnScreen, and for one particular control (I can't remember what type off the top of my head) I have to check a Field value as well as VisibleOnScreen is not accurate for it either.

      • m_essaid's avatar
        m_essaid
        Valued Contributor

         Colin_McCrae

        I'm part of the dev team, and we don't specialy hide objects. but... this script is an example. In my toolbox, in TestComplete, I implemented several scripts that wait for particular properties. but the logic is the same.

        enabled

        enabled and visible

        not visible

        exists

        not exists

        etc etc...

        you could wait several properties one after the other by doing loop into loop.

         

        but again, as a dev I don't hide controls. I just act on some of its properties, and I have the source code to know what I am testing.