Bird
0
0

You want to click a button only if it is visible and enabled. Which Cypress command chain correctly achieves this?

hard📝 Application Q8 of 15
Cypress - Element Interactions
You want to click a button only if it is visible and enabled. Which Cypress command chain correctly achieves this?
Acy.get('button').should('be.disabled').click()
Bcy.get('button').click().should('be.visible').and('not.be.disabled')
Ccy.get('button').click({ force: true })
Dcy.get('button').should('be.visible').and('not.be.disabled').click()
Step-by-Step Solution
Solution:
  1. Step 1: Use assertions before clicking

    To ensure the button is visible and enabled, use should('be.visible') and should('not.be.disabled') before clicking.
  2. Step 2: Chain click after assertions

    After confirming conditions, call .click() to safely click the button.
  3. Final Answer:

    cy.get('button').should('be.visible').and('not.be.disabled').click() -> Option D
  4. Quick Check:

    Assert visibility and enabled before click [OK]
Quick Trick: Assert conditions before click to avoid errors [OK]
Common Mistakes:
  • Clicking before checking visibility
  • Using force click without checking
  • Clicking disabled buttons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes