Which cy.get() selector correctly targets an element with both btn and primary classes?
Remember that chaining classes in CSS selectors means the element must have all those classes.
Option B selects elements with both btn and primary classes. Option B selects elements with either class, not both. Option B uses an ID selector incorrectly. Option B misses the dot for class selectors.
Given cy.get('.menu-item'), which assertion correctly checks that the element is visible?
cy.get('.menu-item')
Visibility means the element is shown on the page, not just present in the DOM.
Option A asserts the element is visible. Option A only checks presence in the DOM. Options C and D check for hidden or non-existent elements, which is opposite of visible.
What does the following code select?
cy.get('nav').get('ul.menu > li.active')cy.get('nav').get('ul.menu > li.active')
Remember that cy.get() always searches the entire document, not scoped to previous commands.
Each cy.get() starts a new search from the document root. So chaining get does not scope the search. Option C is correct. Option C is incorrect because get is not scoped. Option C is wrong. Option C is false; chaining get is valid but not scoped.
Why does cy.get('button#submit.primary') fail to find the element?
cy.get('button#submit.primary')
Check the actual HTML element's classes and ID carefully.
The selector looks for a button element with ID 'submit' and class 'primary'. If the element lacks the 'primary' class, the selector finds nothing. The syntax is valid. If the element tag is different, the selector won't match. Option D explains the most common cause.
In a web app where button classes change dynamically, which selector strategy is best to reliably select the submit button using cy.get()?
Think about selectors that do not break when styles or classes change.
Using a custom data attribute is the most stable and recommended way to select elements in tests. Complex CSS selectors or text-based selectors are fragile and can break easily. Relying on classes that change dynamically is unreliable.