How can I work with elements that belong within an...
# best-practices
g
How can I work with elements that belong within another element ?
Copy code
js
    cy.log("This page has a section split in two columns");
    cy.get("[data-cy='section-two-columns']")
      .scrollIntoView()
      .should("have.length", 1);

    cy.log("Check the left column");
    cy.get("[data-cy='section-two-columns']").then((twoCol) => {
      cy.wrap(twoCol).find("[data-cy='subheader']").should("have.length", 2);
      cy.wrap(twoCol)
        .find("[data-cy='subheader']")
        .each((subheader) => {
          cy.wrap(subheader).invoke("text").should("be.oneOf", titles);
        });
      cy.wrap(twoCol)
        .find("[data-cy='section-content']")
        .should("have.length", 1);

      cy.log("Check right column");
      cy.wrap(twoCol)
        .find("[data-cy='big-info']")
        .should("have.length", 1)
        .contains("234,370");
      cy.wrap(twoCol)
        .find("[data-cy='section-two-columns-icon']")
        .scrollIntoView()
        .should("be.visible");
      cy.wrap(twoCol)
        .find("[data-cy='small-info']")
        .should("have.length", 1)
        .contains("9% increase over 2018");
      cy.wrap(twoCol)
        .find("[data-cy='more-details-url']")
        .should("have.length", 1)
        .contains("See where it happens");
    });
  });
Is it possible to replace:
cy.wrap(twoCol).find("child-element)
and get the element without searching for it using
find
? Can
cy.get()
work "block-scoped" ? Meaning can you write it on some way that it will ONLY get elements that are children of another element ?
2 Views