cancel
Showing results for 
Search instead for 
Did you mean: 

Perform an action stored in a variable over an object

SOLVED
s21_shankar
New Contributor

Perform an action stored in a variable over an object

Imagine the below scenario.

Set myObj = Browser.Page.Obj

Var myAction = "click"

I want to perform the click action in the below fasion

"myObj .myAction "

 

Can someone let me know how this can be done. I have tried to use Eval as well but no luck.

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: Perform an action stored in a variable over an object

And if myObj is an object, like in your example, then something like this should work:

eval(myObj.FullName + '.' + myAction)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
Marsha_R
Community Hero

Re: Perform an action stored in a variable over an object

if myObj and myAction are both strings, then something like this should work:

eval(myObj + '.' + myAction) 

 

 

AlexKaras
Community Hero

Re: Perform an action stored in a variable over an object

And if myObj is an object, like in your example, then something like this should work:

eval(myObj.FullName + '.' + myAction)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

s21_shankar
New Contributor

Re: Perform an action stored in a variable over an object

Nopes as mentiined above myobj is an object and myactiin is a string.

Thanks for the response.
s21_shankar
New Contributor

Re: Perform an action stored in a variable over an object

Thanks for the solution. I will try and let you know if it works.
s21_shankar
New Contributor

Re: Perform an action stored in a variable over an object

@AlexKaras the solution works as charm. Thanks for the solution.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors