Bird
0
0

You want to write a Cypress test that visits a page, fills a form input with id #name, and submits it by clicking a button with class .submit-btn. Which code snippet correctly does this?

hard📝 Application Q8 of 15
Cypress - Basics and Setup
You want to write a Cypress test that visits a page, fills a form input with id #name, and submits it by clicking a button with class .submit-btn. Which code snippet correctly does this?
Acy.get('#name').type('Alice') cy.visit('/form') cy.get('.submit-btn').click()
Bcy.visit('/form') cy.get('.submit-btn').type('Alice') cy.get('#name').click()
Ccy.visit('/form') cy.get('#name').click() cy.get('.submit-btn').type('Alice')
Dcy.visit('/form') cy.get('#name').type('Alice') cy.get('.submit-btn').click()
Step-by-Step Solution
Solution:
  1. Step 1: Order commands logically

    Visit the page first, then fill input, then click submit button.
  2. Step 2: Use correct commands for actions

    Use type() to enter text in input, click() to submit.
  3. Final Answer:

    cy.visit('/form') cy.get('#name').type('Alice') cy.get('.submit-btn').click() -> Option D
  4. Quick Check:

    Correct order and commands = cy.visit('/form') cy.get('#name').type('Alice') cy.get('.submit-btn').click() [OK]
Quick Trick: Visit page first, then type input, then click button [OK]
Common Mistakes:
  • Wrong command order
  • Using click() to type
  • Typing on button element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes