Search code examples
xmltestingxpathsmoke-testing

Getting a specific child of a node using Xpath


I have this code here..

<testcase status="error" name="SMOKETEST_BP" loader-item-id="84d8c3d4-c9e1 4f8d-a690-d18c7c204555">
    <annotations>
       <annotation key="Stage" value="System Test"/>
       <annotation key="Kind" value="Smoketest"/>
       <annotation key="Situation" value="Regression"/>
       <annotation key="Domain" value="OMD"/>
       <annotation key="Business Type" value="Business Partner"/>
       <annotation key="Description" value="Create a new business partner (bp) with document"/>
    </annotations>
</testcase>

I want to get the value of the annotation node that has a key with a value of "Business Type".

What should my Xpath look like? Please help.


Solution

  • You can access attributes via @attrname syntax:

    //annotation[@key='Business Type']/@value