Forum Discussion

John_Laird's avatar
John_Laird
Contributor
9 years ago

how to use wildcards in object paths?

I am trying to click on a button using an object reference. Problem is, there are up to 20 variations of the path to the button. This is the path for button 1:

 

Aliases.ACMConfig.frmMain.panelControl1.superTabControl1.suptabConfiguration.userControlConfiguration1.toolStripContainer2.ToolStripContentPanel.tabObjects.acmObjectView.acmObjectView.DocumentsHost.DocumentContainer.panelMain.panelMain_Container.tabControlOptions.tabConfiguration.userControlAsiCustomDialog.tabControl1.tabPage8.gbMeters.btnReferenceSelect_HourlyMeter1Archive

 

The only difference in buttons 1-20 is that this part in the object path different:

 

gbMeters.btnReferenceSelect_HourlyMeter1Archive

 

So to hard code all 20 it would look like:

gbMeters.btnReferenceSelect_HourlyMeter1Archive

gbMeters.btnReferenceSelect_HourlyMeter2Archive

gbMeters.btnReferenceSelect_HourlyMeter3Archive

...

gbMeters.btnReferenceSelect_HourlyMeter20Archive

 

I tried to substitute a wildcard (*) for 1 so that I would not have to hard code all 20. I am consistently then given an error that TC12 cannot find it. If I substitute the wildcard for a number it works. Not sure what I am doing wrong here.

 

What is the best way to solve this problem?

 

Screen shot of dialog in use:

 

  • Actually... I would take a different approach...

    I'm assuming that the list of HourlyMeternnArchive components is dynamic... that from test run to test run there could be more or less of those items. In that case, I wouldn't use mapping at all for the specific items but, instead, use a FindChild or FindAllChildren  to dynamically find the specific item(s) I want to click on based upon a set of criteria. Mapping it with the wildcard in the criteria and having all the items basically point to the same map is going to result in a lot of ambiguous recognition. In fact, I'd go with FindAllChildren to bring back an array of all the objects and then, using a for loop, click through each one... OR, otherwise use the array to interact with the individual components.  Probably better in the long run than wildcarding things.


     

    [EDIT] even if the list of objects isn't dynamic and is a fixed length, you could still use "FindAllChildren" to create an object in memory containing the list of all the objects.  Then, all you would have to do is reference by index... something like:


     

    //BTW... this is a HORRENDOUS mapping... consider in the Aliases section of NameMapping that you reduce this down to something more manageable
    
    var ChildList = Aliases.ACMConfig.frmMain.panelControl1.superTabControl1.suptabConfiguration.userControlConfiguration1.toolStripContainer2.ToolStripContentPanel.tabObjects.acmObjectView.acmObjectView.DocumentsHost.DocumentContainer.panelMain.panelMain_Container.tabControlOptions.tabConfiguration.userControlAsiCustomDialog.tabControl1.tabPage8.gbMeters.FindAllChildren("WndClass", "ReferenceButton"); //This is just a guess... you would need to fill in proper properties etc
    ChildList(0).Click() //Would click on btnReferenceSelect_HourlyMeter1Archive or whatever is first in the list.. etc.
    • John_Laird's avatar
      John_Laird
      Contributor

      Not quite. I mapped the button control and added the wildcard (*) so that it would accept 1-20 in that section of text as valid but when I click "Highlight" in the "Edit Name Mapping Item" dialog it still throws an error:

       

       

      Still not sure why this is not working.

      • Marsha_R's avatar
        Marsha_R
        Moderator

        I wouldn't expect that to work because asking for the highlight is looking for a particular object with * in it on screen and that doesn't exist.

         

        What it should allow you to do now is put HourlyMeter1 or HourlyMeter2 etc. in a test and not have it tell you that the object doesn't exist.  They will both match the name mapping with HourlyMeter*.