Ask a Question

Is there a way to use a test parameter to locate an element?

Occasional Contributor

Is there a way to use a test parameter to locate an element?

In the project I am looking to automate, we have pages where I can create a new object with a name through the UI that then appears on main page as a link.  The text value of that link is the name of the object.  The link only has a class attribute of 'fieldset-edit-link' and no other attributes I could use to id it.

If I add multiple objects, I get lots of link as above with the same class attribute.

Obviously there could be no links added or one, or many depending on what the test dictates.

Mapping one of these links would give me something like '//a[contains(text(), 'My New FieldSet')]'.

Is there a way I can do something like add a test case parameter name in that locator in place of the name?

So something like this:
'//a[contains(text(), $MyTestParamContainingTheNameIAmAfter)]'

Then, when I add this object as On-Screen Action, it would then give me the option to select what goes in to that variable in the locator (constant, test parameter, variable, last operation result etc).

I am not sure I have explained this very well, but hopefully somebody will get one I am asking 🙂


Community Hero

As you can call your own query for Xpath search, yes, just build your query with your test parameter.


Here MyPage is the page object you want to look in and QueryParameter the text to search for.



function quickSample(MyPage = null, QueryParameter = "") {
  let objectToFind = null;
  if ((MyPage != null) && (QueryParameter != "")) {
    QueryParameter = '//a[contains(text(), "' + QueryParameter + '")]';
    objectToFind = MyPage.EvaluateXPath(QueryParameter);
    if (objectToFind != null)
      objectToFind = (new VBArray(objectToFind)).toArray();
  return objectToFind;


Un sourire et ça repart

Occasional Contributor

Thank you for your help.  Doing it through script and then adding a 'Run script routine' to the test is a good solution.  Just wondered if there was a UI way of doing it through on-screen actions, but this will do just fine.


Thanks again for taking time to reply 🙂

Showing results for 
Search instead for 
Did you mean: