Bird
0
0

Which of the following is the correct syntax to click a button with id submitBtn using Cypress?

easy📝 Syntax Q12 of 15
Cypress - Element Interactions
Which of the following is the correct syntax to click a button with id submitBtn using Cypress?
Acy.click().get('#submitBtn')
Bcy.click('#submitBtn')
Ccy.find('#submitBtn').click()
Dcy.get('#submitBtn').click()
Step-by-Step Solution
Solution:
  1. Step 1: Select the element before clicking

    In Cypress, you must first select the element using cy.get() with the CSS selector, then call .click() on it.
  2. Step 2: Check each option's syntax

    cy.click('#submitBtn') tries to call cy.click() with a selector, which is invalid. cy.find('#submitBtn').click() uses cy.find(), which is not a Cypress command. cy.click().get('#submitBtn') calls cy.click() before selecting, which is incorrect.
  3. Final Answer:

    cy.get('#submitBtn').click() -> Option D
  4. Quick Check:

    Select with cy.get(), then .click() [OK]
Quick Trick: Always use cy.get(selector).click() to click elements [OK]
Common Mistakes:
  • Calling cy.click() directly with a selector
  • Using non-existent commands like cy.find()
  • Calling click() before selecting the element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes