Cypress · Junior · Question 26 of 75
Why can't you write const btn = cy.get('button') and use btn as an element?
- 1Because
cy.getonly works insidedescribeblocks - 2Commands return chainers, not elements; the value comes later
- 3Cypress elements can't be stored in variables of type
const
Show the answer
Correct answer: Commands return chainers, not elements; the value comes later
Explanation
Use .then(($btn) => ...) or chain commands. Aliases with .as() share values between commands.