Cypress get() method find elements based on locators on the page. This method will get one or more DOM elements by selector or alias. The querying behavior of this command is similar to how $(...) works in jQuery.
cy.get(selector); cy.get(alias); cy.get(selector, options); cy.get(alias, options);
- Selector is used to filter matching DOM element
- An alias as defined using the .as() command and referenced with the @ character and the name of the alias.
- Options: You can use 4 options within get: log, timeout, withinSubject and includeShadowDOM
cy.get('div.logo-container a.logo'); cy.get('a[title="Forms"]'); cy.get('li.menu-item');
Here in get command we have specified locators or selectors. Next we will discuss how get is different from find, how to use aliases with get command and how to use get in the .within().