How to call parameter in XPath/JavaScript of an object in TruClient VuGen Script

Hello HPE Experts,

I'm having an object on a web page for which 'visible text' property keep changing on every iteration with known value as pre stored in a .dat file.

(Data file - Opportunity.dat ;; Field Name: Opportunity)

For this, I'm trying to call a parameter value from prestored parameter table to the TruClient object having ID Method JavaScript.

The javascript has been written as below:

evalXPath("//span[text()=\"" ArgsContext.TC.getParam("Opportunity") "\"]");

But object is not getting idenetified.

 

Please help me out in resolving the issue. And welcoming other approaches as well.

Thanks in advance.

Shiv

  • Hello,

    You should stop relying on that predefined value stored in the parameter data file. Instead I recommend switching the object identification to Descriptors and try to modify the properties not to rely on the object text.

    Check this webinar: https://www.youtube.com/watch?v=PStYMuphfqE around the 35th minute for an example of something similar, not identical though. By the way, I recommend watching the whole webinar and other ones in the series.

    Regards,

    Shlomi

     

     

  • Hi Shlomi,

    Thanks for your prompt reply along with providing the link.

    In my scenario, the available properies for a link text are very limited.

    Let me explain the scenario with an example:

    While creating a new request, the request name "Request_001" has been passed from a predefined .dat file. Once the request get generated, it get displayed as a link text "Request_001" on the list pane, where other requests also available but with different names (say: Request_002, Request_003 and so on...).

    Now I want to click on the newly created request link (say: "Request_001") in the scenario flow. Here the visible text already stored in the .dat file, so we can use it as a parameter in Object-JavaScript.

    evalXPath("//span[text()=\"" ArgsContext.TC.getParam("Request_Name") "\"]");

    Actually I'm using the same link at multiple places in a single scenario flow, that why paramterized approach looks easy to me.

    As I'm getting the issue in the above script, please suggest, where I'm doing wrong while calling the parameter in the above script approach.

    Thanks in advance.

    Shiv

  • Hi Shiv,

    It looks like you are doing it right then. Maybe the value returned from the parameter is not the correct value?

    Maybe you should save the value from the parameter to a variable in the script and change the xpath evaluation to use that variable.

    Regards,

    Shlomi

  • Hello Shlomi,

    The script has been written in Evaluate JavaScript Code is as below

    var abc = TC.getParam("Opportunity");

     

    I'm trying to do in a similar way, as to store the parameter value in a variable. But while running the step individually for verification of the step, getting below error:

    ** 66: Evaluate JavaScript code var abc = TC.getParam("Opportunity"); ** failed - exception occurred: API_ERROR_INVALID_ARGUMENTS_RUNTIME: TC.getParam("Opportunity") APIError: Can not be used in "Play this step only" mode

     

    There might be some tips which is unknown to me, Please see if you can help in resolving this issue.

    Thanks

    Shiv

     

     

     

  • TC.getParam requires running the whole script. It does not work when playing a single step since the data is fetched from a different process which is being invoked only when running the whole script.

    I suggest watching TruClient Webinars on YouTube. There are a lot of handy tips, the above one was covered there as well.

    Regards,

    Shlomi

  • Hello all,

    I have similar kind of issue.

    For my case link to be clicked is - kumar123, vivek

    123 is coming from parameter file and will change everytime.

    I have passed parameter value to a variable x. It is working fine till here.

    But when i am trying to click on the link using below xpath it is not able to identify it -

    evalXPath("//a[text()='kumar" ArgsContext.x ", vivek']");

    Is my format correct?

    Please help me with this.

  • Your syntax seems OK. How did you define x? Did you replay the step in which x is being initialized before trying to higlight the object?

    Shlomi