Xpath Expression for the Soap response

Hi guys,

The following is the soap response. How to extract this data bVt7-IgW4-XA2W-w8GS-kbIe-1bth-X3 and store it in a variable TokenValue from the response, using xpath

<S:Envelope xmlns:S=“http://schemas.xmlsoap.org/soap/envelope/”>
<S:Body>
<ns2:registerCustomerResponse xmlns:ns2=“services.evergent.com”>

Nueva Cuenta creada con éxito

cpCustomerId
170614064308126


spAccountId
170614064308140699918699918


orderId



sessionToken
bVt7-IgW4-XA2W-w8GS-kbIe-1bth-X3

SUCCESS

</ns2:registerCustomerResponse>
</S:Body>
</S:Envelope>

i had tried this, but haven’t worked out

.check(xpath("//paramName/paramValue[4]").saveAs(“TokenValue”))

it returned this

---- Errors --------------------------------------------------------------------

Your xpath is wrong. Suggest working out the correct xpath using an online tool such as http://www.xpathtester.com/xpath first, before incorporating in your Gatling script.

Using ordinals, this would get the value you’re after:

//params[4]/paramValue

However, using ordinals is not a good idea because you can’t always guarantee that the fields will not appear in the correct format (depending on schema), or that the response won’t change in future (i.e. if a field gets inserted).

This is a better xpath for what value you’re after:

//params[paramName=‘sessionToken’]/paramValue

Even more efficient would be to use a more explicit XPath, but since there are different namespaces involved that would involve a bit of messing about with the query, which I can’t be bothered to look at - so suggest using the non-ordinal option above.

Cheers,
Barry

Thanks a lot Barry, the code you suggested Worked out. :smile: