Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
Cypress - extract value from XML response

I am having problems retrieving a value from an XML response when using Cypress to make the API request. The API returns a 200, and I can see the response body, as expected, in the browser console.

I have tried the following after much research online, however the 'Price' value returned is undefined.

Guidance would be much appreciated.

/// <reference types="cypress" />

it('Submit test', () => {
    cy
      .readFile('../fixtures/test1.xml')
      .then(fetchXML)
      .then(responseFromXML  => {
          expect(responseFromXML.status).to.eq(200)

      const parser = new DOMParser();
      const xmlDOM = parser.parseFromString(responseFromXML,"text/xml");
      const value = xmlDOM.getElementsByTagName("Price")[0];
      console.log("Extracted value is "+value)
      })
  
    function fetchXML(xml_body) {
      return cy.request({
        url: Cypress.env('test_endpoint'),
        method: 'POST',
        body: xml_body,
        headers: {
          'Content-Type': 'application/xml',
        },
      })
  }
})

Please see sample XML response below. I suspect the issue is with line

const value = xmlDOM.getElementsByTagName("Price")[0];

XML Response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP:Body>
        <tns:CreateV2ResponseParameter xmlns:tns="http://ws.xxx.com/wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <tns:PriceList>
                <tns:PriceDetails>
                    <tns:Price>211</tns:Price>
                </tns:PriceDetails>
            </tns:PriceList>
        </tns:CreateV2ResponseParameter>
    </SOAP:Body>
</SOAP:Envelope>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

looks like you pass incorrect value to the parser here:

parser.parseFromString(responseFromXML,"text/xml");

it should probably be responseFromXML.body:

parser.parseFromString(responseFromXML.body,"text/xml");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!