Forum Discussion

AndyG's avatar
AndyG
Occasional Contributor
4 years ago
Solved

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...
  • BenoitB's avatar
    4 years ago

    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;
    }