Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress: any difference between cy.get("a").find("b") and cy.get("a b")

It seems like they're identical. Is there ever any difference in output between cy.get("a").find("b") and cy.get("a b")?

(Where a and b are some selectors, e.g. div and span, or .someClass and .someOtherClass.)

like image 413
elijahcarrel Avatar asked Aug 30 '18 18:08

elijahcarrel


1 Answers

As you stated in your question there is not difference between cy.get("a").find("b") and cy.get("a b"). But the most important difference between find and get commands in Cypress is that cy.get() is chained off of cy, it always looks for the selector within the entire document as stated in Cypress documents. But as again stated in Cypress documents find works as follows:

Get the descendent DOM elements of a specific selector.

So the command cy.get("a").find("b") returns all the b elements which are successor of an a element, but cy.get("a").get("b") finds all the a and b elements regardless of they are parent and child.

like image 113
RezKesh Avatar answered Sep 24 '22 01:09

RezKesh