Forum Discussion

cbahn001's avatar
cbahn001
Occasional Contributor
9 years ago
Solved

Is it possible to place a variable within an object path and use the Set Variable Value to define?

I have an action to click on a particular button named the following

 

Aliases["LocationManager"]["HwndSource_Window"]["WindowLocationManagerQa20151Version116115C"]["PrismShellWindowContent"]["ContentRegion"]["ModalRegionsControl"]["MainContainer"]["ModalContainer"]["Modal"]["ViewBorder"]["Grid"]["DockPanel"]["Content"]["AreaSelectionRoot"]["ContentControl"]["ContentResolver"]["StationSelection"]["StackPanel"]["CodeSelection"]["StackPanel"]["Grid"]["Grid"]["cropSelection"]["CropSelection"]["grid"]["ListBox"]["ListboxitemCorn"]["StackPanel"]["TextblockCorn"]

 

Is there a way to place a variable at the end of this object path for example 

 

Aliases["LocationManager"]["HwndSource_Window"]["WindowLocationManagerQa20151Version116115C"]["PrismShellWindowContent"]["ContentRegion"]["ModalRegionsControl"]["MainContainer"]["ModalContainer"]["Modal"]["ViewBorder"]["Grid"]["DockPanel"]["Content"]["AreaSelectionRoot"]["ContentControl"]["ContentResolver"]["StationSelection"]["StackPanel"]["CodeSelection"]["StackPanel"]["Grid"]["Grid"]["cropSelection"]["CropSelection"]["grid"]["ListBox"]["ListboxitemCorn"]["StackPanel"][%"CROP"%]

 

Then use Set Variable Value within a keyword test to define what the final path would be like 

 

Set variable Value | CROP [Project] | "TextblockCorn"]

 

This way I could use variables within keyword tests to define which which object I would like to select as I test the application

 

 

 

 

  • We did something similar, but we built a string out of the known part of the object (Aliases["LocationManager"] etc.) and added the variable to the end, then changed that to the object with eval

     

    for example (with your alias string shortened):

     

    set a string variable

    MyCropString = "TextblockCorn"

     

    set an object variable

    MyObjectString = eval("Aliases["LocationManager"]" + Project.Variables.MyCropString)

     

     

     

     

     

2 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    We did something similar, but we built a string out of the known part of the object (Aliases["LocationManager"] etc.) and added the variable to the end, then changed that to the object with eval

     

    for example (with your alias string shortened):

     

    set a string variable

    MyCropString = "TextblockCorn"

     

    set an object variable

    MyObjectString = eval("Aliases["LocationManager"]" + Project.Variables.MyCropString)

     

     

     

     

     

    • cbahn001's avatar
      cbahn001
      Occasional Contributor

      Thanks Marsha_R this worked great for what I was trying to accomplish.