Forum Discussion

AnkushP's avatar
AnkushP
New Contributor
8 years ago

Xpath working in online Xpath tester tools but not working in SoapUI

Dear Community Dwellers, I am trying to write an xpath in  open source SOAPUI version for the below xml.

 

<Group16DetailElectricity>
<Block16DetailElectricity title="Details" energyText="Energie type:" energyType="Elektriciteit" typeProductText="Type product:" typeProduct="Elektriciteit vast TK1" eanCodeText="EAN-code:" eanCode="5400000" distributionText="asdasd:" distribution="" contactNumberText="Gebruikt" periodText="Periode:" periodFrom="2015-01-01" periodTill="20222-09-20" averagePriceText="asdsa:" averagePrice="0.0494" averagePriceUoM="€/kWh" totalDescriptionText="Totaal afrekening elektriciteit:" totalExclVATText="Totaal" totalExclVATText2="(excl. BTW)" totalExclVAT="329.28" totalInclVATText="Totaal" totalInclVATText2="(incl. BTW)" totalInclVAT="398.43">
<Product typeProduct="Elektriciteit vast TK1" periodFrom="20222-01-01" periodTill="2222-ss-20"/>
<ConsumptionTable>
<ConsumptionLine consumptionType="Dag1" consumptionValue="1233" consumptionUoM="kWh"/>
<ConsumptionLine consumptionType="Dag2" consumptionValue="2222" consumptionUoM="kWh"/>
<ConsumptionLine consumptionType="Dag3" consumptionValue="3213" consumptionUoM="kWh"/>
<CosinusPhi consumptionType="Dag1" consumptionValue="1233"/>
</ConsumptionTable>
<TotalEnergyEssentTable tableDescription="Energiekost" periodFrom="2017-01-01" periodTill="2017-09-20" volumeText="Volume" unitPriceText="Eenheidsprijs" amountExclVATText="Excl. BTW" vatPercentText="% BTW" totalTable="329.28">
<TableLine tableLineDescription="Dag1" volume="1233.000" volumeUoM="kWh" unitPrice="0.04015" unitPriceUoM="€/kWh" amountExclVAT="49.50" vatPercent="21.00"/>
<TableLine tableLineDescription="Dag2" volume="3213.000" volumeUoM="kWh" unitPrice="0.04533" unitPriceUoM="€/kWh" amountExclVAT="145.63" vatPercent="21.00"/>
<TableLine tableLineDescription="Dag3" volume="1.000" volumeUoM="jaar " unitPrice="134.15000" unitPriceUoM="€/jaar" amountExclVAT="134.15" vatPercent="21.00"/>
</TotalEnergyEssentTable>
</Block16DetailElectricity>
</Group16DetailElectricity>

 

The xpath I wrote is working fine in all the online websites for xpath testing. Here is the piece if the code: Why i need Xpath? I want to extract the value of attribute - amountExclVAT based on the other attribute value (Dag1/Dag2/Dag3).

 

The xpath i wrote is - 

//Block16DetailElectricity/TotalEnergyEssentTable/TableLine[@tableLineDescription='Dag1']/@amountExclVAT

 

which doesnt work in SOAP UI and gives null response.

 

Though the below xpath 

 

(//@amountExclVAT)[1/2/3] works fine and i can see the result. 

 

But the issue with working Xpath is that the position of the Tableline can change with every new request and we want to map the values specific to the TableLineDecsription with the previous XML. So the working soulution is not handy in this solution.

 

My question is why my Xpath is not working in SoapUI and giving null error.

 

Any help is appreciated.

 

Thanks,

Ankush

  • Thanks Paul, have found the solution, have to consider namespace in the xpath, this one worked:

     

    //*:Block16DetailElectricity/*:TotalEnergyEssentTable/*:TableLine[@tableLineDescription = 'Verkoopprijs - dag']/@amountExclVAT

  • PaulMS's avatar
    PaulMS
    Super Contributor

    The xpath match assertion works correctly in version 5.3.0 with

    //Block16DetailElectricity/TotalEnergyEssentTable/TableLine[@tableLineDescription='Dag1']/@amountExclVAT

    The result is 49.50.

     

    Are you using xpath match assertion or script assertion?

     

     

    • AnkushP's avatar
      AnkushP
      New Contributor

      Also, using this xpath gives a null result.

      • PaulMS's avatar
        PaulMS
        Super Contributor

        Is @tableLineDescription='Verkoopprijs - dag' the correct attribute in the source property XML?

        The XML example above is different with @tableLineDescription='Dag1'

         

        If the attribute matches the xpath selection then the property transfer should work.

    • AnkushP's avatar
      AnkushP
      New Contributor

      Thank You Paul for the reply. I am using Property Transfer step and then extracting value of the xml tags and attributes using Xpath filter and then saving the value in the Target property.

       

      I am not using Xpath assertion as in my case I need to extract all the values from   each and every step and then compare as explained in the main question.