Forum Discussion

Soni's avatar
Soni
Occasional Contributor
8 years ago

find object search criteria ContentText - can I use Variable value to compare?

Find Object - for the Search Criteria I  am using ContentText  as Property Name , in the Value I  have been using a Constant value.Is it possible to use variable  here whose value will be used as the ContentText to Find Object?

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I don't think you can.  This would be a good thing to have but currently this is not supported with that operation.  This is one of the drawbacks I find to Keyword tests in that they are VERY specifically about making sure everything is mapped.  Finding an object dynamically or parameterized is a bit tricky.  You need at least three operations to do anything meaningful.

    First, you need to do a Call Object Method and call the "Find" method on your parent object.  This you can then parameterize this as much as you want for the properties.

    Next, use a Set Variable Value to set the value of a local variable to your test.  Set the value of the variable to Last Operation Result

    And then, finally, you will need to use a Run Code Snippet to actually do anything with that.  You basically reference the variable in a single line of code to perform the action you want.

    of course, all this depends upon what EXACTLY you are doing with the object you found.  If you're looking for the object to perform an action, what I described is the best way that I know of to do it.  If you are checking existence or properties, some different things can be done.  

    Personally, if I need to find an object dynamically and I'm using keyword tests, I create a helper script in whatever code langauge my project is in and use that script to do what I need to do dynamically.  I find this, personally, less tricky.