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
You can use the
regex
in python: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 differentThis 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.