# Map input values
Let's grab all input fields and see if we can confirm their values. 📺 Watch this recipe explained in the video Map Input Elements Values (opens new window).
Let's grab the form input elements and get the value from each one. We can get the "value" property from each HTML input element.
const expectedValues = [
'Joe',
'Smith',
'01-20-1999',
'male',
'female',
'',
'abc1234',
'abc1234',
'',
'Submit',
]
cy.get('#signup-form input')
.then(($inputs) => Cypress._.map($inputs, (el) => el.value))
.should('deep.equal', expectedValues)
The above code would fail if the values are set after a delay, since cy.then
does not retry. We could write the entire extraction code in the should(callback)
function to enable retries:
cy.get('#signup-form input').should(($inputs) => {
const values = Cypress._.map($inputs, (el) => el.value)
expect(values).to.deep.equal(expectedValues)
})
We can also write the same code using cypress-map (opens new window) to take advantage of query chains in Cypress v12+.
cy.get('#signup-form input')
.map('value')
.should('deep.equal', expectedValues)