Cypress - Selecting ElementsWhat is wrong with this Cypress selector?cy.get('.button primary')AIt will select elements with class 'button' or 'primary'BIt tries to select an element with class 'button primary' but uses incorrect syntaxCIt correctly selects elements with both classes 'button' and 'primary'DIt selects elements by id 'button primary'Check Answer
Step-by-Step SolutionSolution:Step 1: Understand CSS class selector syntaxMultiple classes must be concatenated with dots, no spaces: '.button.primary'Step 2: Identify the errorUsing a space selects descendant elements, so '.button primary' looks for 'primary' tag inside '.button' class, which is invalid here.Final Answer:It tries to select an element with class 'button primary' but uses incorrect syntax -> Option BQuick Check:Multiple classes need dot concatenation, no spaces [OK]Quick Trick: Use .class1.class2 for multiple classes, no spaces [OK]Common Mistakes:Using space instead of dot between classesConfusing class selectors with id selectorsAssuming space means 'or' in selectors
Master "Selecting Elements" in Cypress9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepTraceTryChallengeAutomateRecallFrame
More Cypress Quizzes Assertions - expect() for BDD assertions - Quiz 2easy Cypress Basics and Setup - Cypress vs Selenium vs Playwright comparison - Quiz 8hard Cypress Basics and Setup - Why Cypress is built for modern web testing - Quiz 6medium Element Interactions - cy.click() - Quiz 10hard Element Interactions - cy.clear() for input fields - Quiz 2easy Navigation and URL - cy.url() assertions - Quiz 12easy Selecting Elements - data-cy attributes for test stability - Quiz 1easy Writing Tests - beforeEach and afterEach hooks - Quiz 12easy Writing Tests - Skipping and focusing tests (.skip, .only) - Quiz 14medium Writing Tests - Test naming conventions - Quiz 3easy