0
0
Cypresstesting~10 mins

cy.first(), cy.last(), cy.eq() in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the first item in the list using Cypress.

Cypress
cy.get('ul > li').[1]().should('have.length', 1)
Drag options to blanks, or click blank then click option'
Afirst
Blast
Ceq
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'last()' instead of 'first()' selects the last element, not the first.
Using 'eq()' without an index will cause an error.
2fill in blank
medium

Complete the code to select the last button on the page using Cypress.

Cypress
cy.get('button').[1]().should('be.visible')
Drag options to blanks, or click blank then click option'
Aeq
Blast
Cfirst
Dchildren
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'first()' selects the first element, not the last.
Using 'eq()' without specifying an index will not work.
3fill in blank
hard

Fix the error in the code to select the third item in the list using Cypress.

Cypress
cy.get('li').[1](2).should('contain.text', 'Item 3')
Drag options to blanks, or click blank then click option'
Aeq
Bfilter
Clast
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'first()' or 'last()' selects only the first or last element, not the third.
Using 'filter()' requires a selector, not an index.
4fill in blank
hard

Fill both blanks to select the second item and check it contains the correct text.

Cypress
cy.get('ul > li').[1]([2]).should('contain.text', 'Second item')
Drag options to blanks, or click blank then click option'
Aeq
B1
C2
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 selects the third item, not the second.
Using 'first()' selects the first item, not the second.
5fill in blank
hard

Fill all three blanks to select the last item, check its text, and then select the first item.

Cypress
cy.get('li').[1]().should('contain.text', [2]); cy.get('li').[3]().should('exist')
Drag options to blanks, or click blank then click option'
Alast
B'Last item'
Cfirst
Deq
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'eq' without an index will cause an error.
Mixing up 'first()' and 'last()' commands.