Skip to main content

Cypress Get Command

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.

Syntax:

cy.get(selector);
cy.get(alias);
cy.get(selector, options);
cy.get(alias, options);

Here:

  • 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

Example:

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().

Tags
Submitted by tgoswami on May 30, 2021

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.