JMeter Xpath2 extractor id's matching multiple conditions

Viewed 113

Below is the sample XML fragment, from it i'm trying to filter out id's of articles matching both conditions as below. Currently i could extract id's for individual condition with help of expression below

  1. get Avaialable articles, Xpath2 expression = (//*//*//*//*[starts-with(state,'Avaialable')])/id
  2. get articles name starting with 'A' () , Xpath2 expression = (//*//*//*//*[starts-with(name,'A')])/id

I want to merge these conditions in a single expression and would like to

fetch id's of Articles where Name starts with 'A' AND articles which are Available

. Tried multiple ways but not working as expected.

Dummy XML fragment:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:GetArtclesResponse
    xmlns:ns2="XXX"
    xmlns:ns4="XXX"
    xmlns:ns3="XXX"
    xmlns:ns6="XXX"
    xmlns:ns5="XXX"
    xmlns:ns8="XXX"
    xmlns:ns7="XXX"
    xmlns:ns13="XXX"
    xmlns:ns9="XXX"
    xmlns:ns12="XXX"
    xmlns:ns11="XXX">
    <serverTimeInfo timezone="+00:00" timestamp="1606409365419"/>
    <items>
        <count>2</count>
        <articles>
           <article>
                <name>ABC</name>
                <id>1234</id>
                <state>Avaialable</state>
            </article>
            <article>
                <name>XYZ</name>
                <id>3456</id>
                <state>Avaialable_Conditional</state>
            </article>
        </articles>
    </items>
</ns3:GetArtclesResponse>
2 Answers

You can use and to check both:

(//*//*//*//*[starts-with(state,'Avaialable') and starts-with(name,'A')])/id
  1. If you want to combine 2 different XPath expressions you can use | (union) operator like:

     //article[state = 'Avaialable']  |  //article[starts-with(name,'A')]
    

    it will return you both:

    • nodes which have state=Available
    • and nodes which name starts with A
  2. If you want to combine 2 conditions in a single XPath expression - go for and operator like:

    //article[state = 'Avaialable' and starts-with(name,'A')]
    

    it will return

    • nodes which nave state=available and whose name attribute starts with a

More information:

Related