Forum Discussion

ioioio's avatar
ioioio
Occasional Contributor
8 years ago
Solved

Construct a object if I know the object name

Hi,

 

I have the following call:

 

Call Aliases.browser.page.formForm0.radiobutton1YearSubscription.ClickButton

where radiobutton1YearSubscription is a radio button in a form. In the same form i have another 2 radio buttons radiobutton2YearSubscription3600 and radiobutton3YearSubscription2400

 

 

I want to call the click method after a if statment like this:

 

If (y="1y") then
BTNy="radiobutton1YearSubscription"
elseif (y="2y") then
BTNy="radiobutton2YearSubscription3600"
elseif (y="3y") then
BTNy="radiobutton3YearSubscription2400"
End If

 

Call Aliases.browser.page.formForm0.BTNy.ClickButton

 

How can I construct the object knowing the button names?

 

Thanks

  • Hi,

     

    All scripting languages have an equivalent of the evaluate() or eval() function that accepts a string, executes it as code and returns a result.

    The code for your case will be like that (VBScript pseudocode that should be adjusted to match the language used in your project):

    ...
    BTNy = "radiobutton1YearSubscription"
    ...
    
    strObjAlias = aqString.Format("Aliases.browser.page.formForm0.%s", BTNy)
    Set oObj = Evaluate(strObjAlias)
    If (oObj.Exists) Then
      Call oObj.ClickButton()
    Else
      ...
    End If
    

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    All scripting languages have an equivalent of the evaluate() or eval() function that accepts a string, executes it as code and returns a result.

    The code for your case will be like that (VBScript pseudocode that should be adjusted to match the language used in your project):

    ...
    BTNy = "radiobutton1YearSubscription"
    ...
    
    strObjAlias = aqString.Format("Aliases.browser.page.formForm0.%s", BTNy)
    Set oObj = Evaluate(strObjAlias)
    If (oObj.Exists) Then
      Call oObj.ClickButton()
    Else
      ...
    End If
    
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I think, for Aliases, you can still do a "FindChild" call. If you don't like doing eval calls, you can try that.
    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      > for Aliases, you can still do a "FindChild" call.

      With 'WaitAliasChild' probably been a more relevant option...

      • ioioio's avatar
        ioioio
        Occasional Contributor

        Thanks.

         

        Eval(string) did the trick.