0
0
Cypresstesting~5 mins

cy.get() with CSS selectors in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does cy.get() do in Cypress?

cy.get() finds elements on the page using CSS selectors. It lets you select elements to test or interact with.

Click to reveal answer
beginner
How do you select an element with the class button-primary using cy.get()?
<p>Use <code>cy.get('.button-primary')</code>. The dot <code>.</code> means class in CSS selectors.</p>
Click to reveal answer
beginner
How to select an element with the ID login-form using cy.get()?

Use cy.get('#login-form'). The hash # means ID in CSS selectors.

Click to reveal answer
intermediate
What is the best practice for writing CSS selectors in cy.get()?

Use unique and stable selectors like IDs or data attributes (e.g., [data-cy='submit-btn']) to avoid flaky tests.

Click to reveal answer
intermediate
How can you select a button element with text Submit using cy.get() and CSS selectors?

CSS selectors alone can't select by text. Use cy.contains('button', 'Submit') instead.

Click to reveal answer
Which CSS selector would you use with cy.get() to select all elements with class item?
A.item
B#item
Citem
D*item
How do you select an element with ID header using cy.get()?
A#header
Bheader
C.header
D*header
Which selector is best to avoid flaky tests in cy.get()?
ARandom class names
BTag names only
CUsing text inside CSS selectors
DData attributes like <code>[data-cy='btn']</code>
Can cy.get() select elements by their visible text using CSS selectors alone?
AYes, with <code>text()</code>
BYes, with <code>:contains()</code>
CNo, CSS selectors can't select by text
DYes, with <code>cy.getText()</code>
What does cy.get('button.submit-btn') select?
AAll <code>button</code> elements
BAll <code>button</code> elements with class <code>submit-btn</code>
CAll <code>submit-btn</code> elements
DAll elements with class <code>submit-btn</code>
Explain how cy.get() uses CSS selectors to find elements on a page. Include examples for class and ID selectors.
Think about how you pick elements in CSS styles.
You got /4 concepts.
    Describe best practices for writing selectors in cy.get() to make tests reliable and easy to maintain.
    Think about what makes a selector stable when the page changes.
    You got /4 concepts.