skip to Main Content

I’m currently working on API testing. The API that I’m testing is returning an HTML body. How do I get an element from the response body? If I visit the link, it returns an iframe and I cannot access it properly inside cy.origin.

How to get the https://test-develop.test.net/download/cd668080-be63-11ed-8328-41d4c5da193d or the XudSov7Y6JDm ? I’ve been going through this for hours but can’t seem to find a solution :/

var message = `<html>

<body style="background-color:#f5f5f5;font-family:'Open Sans',sans-serif;padding:24px 0;">
    <div style="margin:0 auto 24px auto;text-align:center">

        <img width="130" src="cid:quipper_logo" alt="School LINK" />

  </div>
        <hr style="border:none;" />
        <div style="margin:12px auto;max-width:540px;background-color:white;border:1px #dcdcdc solid;padding:20px;">
            <p><strong>** This email is automatically generated. Please do not reply. **</strong></p>


            <p>Your Excel spreadsheet for is ready to download.</p>



            <p>Please note: you will need to enter the supplied username and password to download the file.</p>




            <p><strong>Download:</strong> <a
                    href="https://test-develop.test.net/download/cd668080-be63-11ed-8328-41d4c5da193d">https://test-develop.test.net/download/cd668080-be63-11ed-8328-41d4c5da193d</a>
            </p>


            <p>Username: [email protected]</p>
            <p>Password: XudSov7Y6JDm</p>



        </div>
</body>

</html>`

2

Answers


  1. You can use the regex in python:

    import re
    
    message = # insert you HTML Body 
    link = re.search(r'https://S+', message).group(0)
    password = re.search(r'Password: (S+)', message).group(1)
    print(download_link)
    print(password)
    
    Login or Signup to reply.
  2. Please see this answer How can I check the src attribute of every script tag in an html document that uses DOMParser to extract elements from the HTML string.

    In your case there’s one <a>, so slightly different

    const parser = new DOMParser();
    const doc = parser.parseFromString(message, 'text/html')
    const href = doc.querySelector('a').href
    

    This is broadly the way to do it, but I’m a bit worried about the reference to cy.origin() as there are some things that don’t work inside that command.

    In any case give it a spin, if not working update details of that origin call.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search