1

I'm trying to retrieve several input values from Cypress, ideally as an array. For instance, if I have:

<input type="email"> <input type="password"> 

Assuming that these fields are already filled with the values "[email protected]" and "mypassword", I'd like to get the array ["[email protected]","mypassword"] as a result.

I've tried:

cy.get("input").each($el => $el.text()) 

But, as indicated in Cypress docs, the "each" function always returns the elements it was called with, no matter what's returned from it. I've tried other solutions but nothing seems to work.

How would you go about doing this? Thanks in advance.

1 Answer 1

1

You can use Array.from in combination with then to get the array.

cy.get("input").then(($els) => { const texts = Array.from($els, el => el.innerText); cy.log(texts) //Your array }) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.