[WS] Get Element Property Value for ${index} object

Hi,

Could you please let me know if it is possible to get a value of some index* object ( [WS] Get Element Property Value )? Or I need to parse json for this?

  • index of array in json

use case:
I have an array of objects in json (rest api response)
I need a value of [index] object
I try to use a variable. I am not sure if the syntax is a problem or it is just not possible with
[WS] Get Element Property Value

Thank you in advance for your answers.

1 Like

(since tracksData[33] already works)

…you already initialized the track = 33 variable so you don’t have to use the sneaky ${} interpolation, which is for other use cases (e.g. in parametrized fields)

just do tracksData[track].wear_in in your code snipet as the 'track` variable now already have the value of your intended index

1 Like

@anon46315158 thank you for your answer.
something is still wrong. Var is not recognized.

Ah, my bad. You are using the getElementPropertyValue keyword which needs a string as an argument for the locator … so indeed you may need interpolation.
However for this to work you have to use double quotes.

Try this:

testVar =  WS.gelElementPropertyValue(response, "tracksData[${track}.wear_in]")

See the difference between:

int track = 33
println ('Some[${track}]')

println ("Some[${track}]")

output:

2023-12-21 12:13:52.548 DEBUG testcase.                                - 4: track = 33
2023-12-21 12:13:52.550 DEBUG testcase.                                - 5: println("Some[${track}]")
Some[${track}]
2023-12-21 12:13:52.554 DEBUG testcase.                                - 6: println(Some[$track])
Some[33]

Alternate, you can use concatenation to build your locator string.

1 Like

@anon46315158 Thank you! It works:

testVar = WS.getElementPropertyValue(response, "tracksData[${track}].wear_in")

1 Like