Challenge - 5 Problems
Chaining Selectors Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this chained selector test?
Consider the following Cypress test code snippet. What will be the result of the assertion?
Cypress
cy.get('form#login').find('input[type="text"]').should('have.length', 2)
Attempts:
2 left
💡 Hint
Remember that chaining selectors narrows down the search within the previous element.
✗ Incorrect
The 'get' command selects the form with id 'login'. The 'find' command searches inside that form for input elements of type text. The assertion checks that exactly 2 such inputs exist inside that form. This is valid chaining and assertion.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the chained selector result?
You have chained selectors to get all buttons inside a div with class 'container'. Which assertion correctly checks that there are 3 buttons?
Cypress
cy.get('div.container').find('button')
Attempts:
2 left
💡 Hint
Check the assertion that verifies the number of elements found.
✗ Incorrect
The 'have.length' assertion checks the number of elements matched by the chained selector. The others check text content or existence incorrectly.
❓ locator
advanced2:00remaining
Which chained selector correctly finds all visible links inside a nav with id 'main-nav'?
Choose the correct Cypress chained selector to find all visible elements inside the nav with id 'main-nav'.
Attempts:
2 left
💡 Hint
Remember that Cypress does not support jQuery pseudo selectors directly in 'find'.
🔧 Debug
advanced2:30remaining
Why does this chained selector test fail with 'Cannot read property' error?
Analyze the code below and select the reason for the failure:
cy.get('.list').find('li').first().click().find('button').click()
Attempts:
2 left
💡 Hint
Consider what commands return and how chaining works in Cypress.
✗ Incorrect
In Cypress, commands like 'click()' do not return a chainable subject but a promise-like object. Chaining 'find' after 'click()' is invalid and causes a runtime error.
❓ framework
expert3:00remaining
In Cypress, what is the correct way to chain selectors and assertions to verify a nested element's text?
You want to check that a inside a
contains the text 'Success'. Which chained Cypress code is correct?
Attempts:
2 left
💡 Hint
Think about the order of chaining and where assertions apply.
✗ Incorrect
Option A correctly chains 'find' to get the span inside the div and asserts its exact text. Option A asserts text on the div, not the span. Option A uses a selector string but does not chain. Option A uses 'contains' as a command, which is valid but does not assert text equality.