Search code examples
xmlrobotframeworkparsexml

How to read the XML response element in robot framework?


I have run SOAP API request and get the response as below using robot framework.

(reply){
   return = "PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS"
}

I would like to retrieve the value PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS from the response XML. I have tried to get the value using the command

${token}=    Set Variable    ${API_response_Data.return} 

But it throws an error

SyntaxError: unexpected EOF while parsing (<string>, line 1)

The actual response from the SOAP UI tools looks like below (This is just for reference).

<soapenv:Envelope xmlns:soapenv="something" xmlns:xsd="something">
   <soapenv:Body>
      <ns1:response xmlns:ns1="http://something.com">
         <return>PGP-98-Sq0awmdslfjsdssdlsifTvZUORTLe1fgVeUwaolR14QS</return>
      </ns1:response>
   </soapenv:Body>
</soapenv:Envelope>

I have used Parse XML keyword and I get the below error. enter image description here

and when I use

 ${Token}=    Get Element    ${API_response_Data}    .//*return
    Log    ${Token.text}

I get the below error. enter image description here

Please let me know how to extract the value from the return tag?


Solution

  • The SudsLibrary depends on the Suds module. Sadly this module is no longer maintained and as time passes the limitations of this module are becoming clearer.

    In your case the object that is returned is difficult to use. This is why I preferred to have the XML response returned and process it myself using the standard XML library.

    Before sending the request you can use the Set Return XML keyword to enable this. Then follow the example in the XML library for keyword Parse XML to obtain the actual value