Getting specific text from xml formatted data from a web URL

I am looking for a way to extract a specific information and saving it in a String variable. The scenario is the test opens a new browser and hits the URL. This URL creates dynamic IDs of one of the tags that I need to input my test so I cannot parse through an already saved xml file.

I hit the URL and the xml loads like this:

<gift_card_issue_response>
    <gift_card_issue_status>00</gift_card_issue_status>
    <gift_card_issue_result>00GOOD </gift_card_issue_result>
    <gift_card_issue_response_data>
        <CardNumber443322</CardNumber>
        <PinNumber>322</PinNumber>
        <CardType/>
    </gift_card_issue_response_data>
</gift_card_issue_response>

I need to extract the the card number and pin number and save them in variables. I tried to access the elements using the css selector or xpath, but it would not locate the tags on the page.

Does someone has some idea how I can extract these texts from the web page itself?

This is not a well-formed XML.

You can not process this using usual XML processing technologies like XPath.

Provided the xml is properly formated (let’s assume you had a mistake in your post when you copy/pasted the code) you can use XmlParser or XmlSlurper to extract the value needed.
see:
https://groovy-lang.org/processing-xml.html

String xml = """
<gift_card_issue_response>
<gift_card_issue_status>00</gift_card_issue_status>
<gift_card_issue_result>00GOOD </gift_card_issue_result>
<gift_card_issue_response_data>
<CardNumber>443322</CardNumber>
<PinNumber>322</PinNumber>
<CardType/>
</gift_card_issue_response_data>
</gift_card_issue_response>
"""

def parsed = new XmlSlurper().parseText(xml)
def cardNumber = parsed.gift_card_issue_response_data.CardNumber
assert cardNumber = "443322"