Cypress · Junior · Question 26 of 75

Why can't you write const btn = cy.get('button') and use btn as an element?

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.

Further reading

Problem with a question

Cypress · Junior · question 26

Test yourself

Take the Cypress · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz