Forum Discussion

jlewi1's avatar
jlewi1
New Contributor
9 months ago

Xpath Assertion with only Child gives 'null' instead of the value from the Child".

 

x-Path Assertion:

For a request with only one child the response is "null" as expected result instead of the value of the parent. See attached screenshot:
Ready Api Version 3.47.0 is being used.

 

thanks in advance,

Greetings,

 

Julius

2 Replies

  • richie's avatar
    richie
    Community Hero

    Hey jlewi1 

     

    I can't attempt to reproduce right now - all my responses are in JSON, but I was gonna add in the Accept header to my requests to switch the response to XML, but literally as soon as made the header changes and I attempted to retrieve my response in XML instead of JSON, my DEV environment just dropped and it'll be tomorrow before it's back up (and I don't have a LOCAL to play with)

     

    In the meantime however, it's been a while since I worked with XPATH/XML, but I'll do my best. 

     

    First thing - I'm a little confused - you state in your post "For a request with only one child the response is "null" as expected result instead of the value of the parent."

     

    When you say "instead of the value of the parent" - I'm confused - there is no parent to the <Collection> tag - that is the containing tag for all other elements in your payload - i.e. in your screenshot - the <Collection> tag doesn't have a parent.

     

    Also - in regards to the assertion - it looks like it's asserting on the value of the <Collection> tag and reporting null because the <Collection> tag doesn't actually have a value - it's a container tag, so I'd expect it to report as null.  I admit, I am out of practice with XPATH/XML (i.e. I'd forgotten about the indices starting at 1 with XML, whereas they start with 0 with JSON), so I could be wrong - but I think the logic follows about the value of the <Collection> tag being null.

     

    I'm curious - if you have >1 record (e.g. 2) in the <Collection> tag - so the reported XPATH of the <Collection> tag would appear as //Collection[2] - what value is the auto generated expected result- are you saying it differs from null?

     

    OK - that's all I got right now!

     

    Cheers,

     

    Rich

  • KarelHusa's avatar
    KarelHusa
    Champion Level 2

    jlewi1,

    your XPath expression:

     //collection[1] 

    should really select the collection XML node.