Forum Discussion

yogeshk's avatar
yogeshk
New Contributor
11 years ago

Unable to get xpath

Hi All,
I am new to SOAP UI automation and got stuck with an issue related to xpath.
From response xml i am unable to get the elements values using xpath. below is the response xml and i need to get the value of 'orderId' element.
I tried below from groovy script but not working.
context.expand('//orderId') and context.expand('//submitProductOrderOutput /orderId')
If the remove the content highlighted in below xml in bold then its working.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<submitProductOrderOutput xmlns:ns2="http://harlequins.bt.com/schema/CommonMessages" xmlns="http://harlequins.bt.com/schema/OUKMessages">
<responseStatus>
<ns2:responseStatus>SUCCESS</ns2:responseStatus>
<ns2:responseStatusCode>PROV100</ns2:responseStatusCode>
<ns2:responseStatusText>SUBMIT PRODUCT ORDER SUCCESS</ns2:responseStatusText>
</responseStatus>

<orderId>157642</orderId>
<orderValid>true</orderValid>
<customerId>41992</customerId>
<estimatedLeadTime>2014-08-21T00:00:00.000+01:00</estimatedLeadTime>
<appointmentReferences>027C10ST</appointmentReferences>
</submitProductOrderOutput>
</soap:Body>
</soap:Envelope>

5 Replies

  • nmrao's avatar
    nmrao
    Community Hero
    It was becuase orderId is using default namespace.

    Here you go:

    Declare the namespace for "http://harlequins.bt.com/schema/OUKMessages" with a prefix
    Then access the node using that prefix.

    Following Sample groovy script placed after soap request test step whose name is Request.

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "Request#Response" )
    holder.namespaces["ns"] = "http://harlequins.bt.com/schema/OUKMessages"
    def orderIdValue = holder.getNodeValue("//ns:orderId")
    log.info "Order ID from response : ${orderIdValue}"
  • yogeshk's avatar
    yogeshk
    New Contributor
    Hi Rao,
    Tried your code now. Thanks a lot . It's working fine.

    Regards,
    Yogesh.K
  • yogeshk's avatar
    yogeshk
    New Contributor
    Hi Rao,

    Could you please help me out in another issue. I have attached response xml. in that, i have element named 'id'. there are duplicates in the xml. total 19 are there. i used below to get value of id but not working. i could get the total count value but i am not able to get value of each id. please help. Attaching xml.

    import com.eviware.soapui.support.XmlHolder
    def response=context.expand('${GAPO_DN#response}')
    def xml=new XmlHolder(response)
    xml.namespaces["ns"]="http://harlequins.bt.com/schema/OUKMessages"
    arr=xml.getNodeValues('//ns:id')
    log.info arr.length //getting correct value 19 here
    for(int i=1;i<=arr.length;i++){
    log.info xml.getNodeValue('//ns:id') // null is getting displayed
    }
  • nmrao's avatar
    nmrao
    Community Hero
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "Request#Response" )
    holder.namespaces["ns"]="http://harlequins.bt.com/schema/OUKMessages"
    def arr=holder.getNodeValues('//ns:id')
    log.info arr.length //getting correct value 19 here
    for(int i=0;i<arr.length;i++){
    log.info arr[i] //array has all the values
    }