0
0
Cypresstesting~20 mins

cy.click() in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Click Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the result of this Cypress test snippet?

Consider the following Cypress test code. What will be the test execution result?

Cypress
cy.get('button#submit').click();
AThe button with id 'submit' is clicked and the test passes if the button exists.
BThe test fails because 'button#submit' is an invalid selector.
CThe test throws a syntax error because 'click' needs parentheses.
DThe test does nothing because 'click' is not a valid Cypress command.
Attempts:
2 left
💡 Hint

Remember that cy.get() finds elements and click() simulates a click.

assertion
intermediate
2:00remaining
Which assertion correctly verifies a button was clicked?

You want to check that clicking a button changes its text to 'Clicked!'. Which assertion is correct?

Cypress
cy.get('button#action').click();
Acy.get('button#action').should('contain', 'Click');
Bcy.get('button#action').should('have.text', 'Clicked!');
Ccy.get('button#action').click().should('have.value', 'Clicked!');
Dcy.get('button#action').should('be.visible').click();
Attempts:
2 left
💡 Hint

Check the text content after clicking the button.

locator
advanced
2:00remaining
Which locator is best for clicking a button with dynamic classes?

You need to click a button that has a dynamic class name but a stable data attribute data-cy='submit-btn'. Which locator is best?

Acy.get('button[data-cy="submit-btn"]').click();
Bcy.get('button.submit-btn').click();
Ccy.get('button[class^="btn-"]').click();
Dcy.get('button#submit').click();
Attempts:
2 left
💡 Hint

Use stable attributes for selectors to avoid flaky tests.

🔧 Debug
advanced
2:00remaining
Why does this Cypress click command fail?

Given the code below, why does the click command fail?

Cypress
cy.get('button#save').click(); // fails with 'element is not visible' error
ACypress does not support clicking buttons with ids.
BThe selector 'button#save' is invalid and finds no element.
CThe button is hidden or covered, so Cypress cannot click it.
DThe click command is missing parentheses.
Attempts:
2 left
💡 Hint

Check if the element is visible and not covered by other elements.

framework
expert
3:00remaining
What is the effect of chaining multiple clicks in Cypress?

Consider this code snippet:

cy.get('button#multi').click().click().click();

What happens when this runs?

AThe clicks happen simultaneously causing unpredictable behavior.
BOnly the first click happens; the rest are ignored due to Cypress command queue behavior.
CThe test throws a runtime error because multiple clicks are not allowed in one chain.
DThe button is clicked three times sequentially, each click waits for the previous to finish.
Attempts:
2 left
💡 Hint

Remember how Cypress queues commands and executes them one by one.