首页 > 解决方案 > 赛普拉斯:cy.get("a").find("b") 和 cy.get("a b") 之间的任何区别

问题描述

似乎它们是相同的。cy.get("a").find("b")和之间的输出有什么区别cy.get("a b")吗?

(其中aandb是一些选择器,例如divand span,或.someClassand .someOtherClass。)

标签: javascriptcypress

解决方案


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.


推荐阅读