# Traversal

Examples of traversing DOM elements in Cypress, for a full reference of commands, go to docs.cypress.io

#### .children()

To get children of DOM elements, use the `.children()` command.

    cy.get('.traversal-breadcrumb')
      .children('.active')
      .should('contain', 'Data')

#### .closest()

To get the closest ancestor DOM element, use the `.closest()` command.

    cy.get('.traversal-badge')
      .closest('ul')
      .should('have.class', 'list-group')

- 14 Events
- 54 Friends

#### .eq()

To get a DOM element at a specific index, use the `.eq()` command.

    cy.get('.traversal-list>li')
      .eq(1).should('contain', 'siamese')

- tabby
- siamese
- persian
- sphynx
- burmese

#### .filter()

To get DOM elements that match a specific selector, use the `.filter()` command.

    cy.get('.traversal-nav>li')
      .filter('.active').should('contain', 'About')

#### .find()

To get descendant DOM elements of the selector, use the `.find()` command.

    cy.get('.traversal-pagination').find('li').find('a').should('have.length', 7)

#### .first()

To get the first DOM element within elements, use the `.first()` command.

    cy.get('.traversal-table td')
      .first().should('contain', '1')

# | First Name | Last Name
--- | --- | ---
1 | Jane | Lane
2 | John | Doe

#### .last()

To get the last DOM element within elements, use the `.last()` command.

    cy.get('.traversal-buttons .btn')
      .last().should('contain', 'Submit')

Link

#### .next()

To get the next sibling DOM element within elements, use the `.next()` command.

    cy.get('.traversal-ul')
      .contains('apples').next().should('contain', 'oranges')

- apples
- oranges
- bananas

#### .nextAll()

To get all of the next sibling DOM elements within elements, use the `.nextAll()` command.

    cy.get('.traversal-next-all')
      .contains('oranges')
      .nextAll().should('have.length', 3)

- apples
- oranges
- bananas
- pineapples
- grapes

#### .nextUntil()

To get all of the next sibling DOM elements within elements until another element, use the `.nextUntil()` command.

    cy.get('#veggies')
      .nextUntil('#nuts').should('have.length', 3)

- Fruits
- apples
- oranges
- bananas
- Vegetables
- cucumbers
- carrots
- corn
- Nuts
- walnuts
- cashews
- almonds

#### .not()

To remove DOM element(s) from the set of elements, use the `.not()` command.

    cy.get('.traversal-disabled .btn')
      .not('[disabled]').should('not.contain', 'Disabled')

#### .parent()

To get parent DOM element of elements, use the `.parent()` command.

    cy.get('.traversal-mark')
      .parent().should('contain', 'Morbi leo risus')

Morbi leo risus, porta ac consectetur ac, highlight vestibulum at eros.

#### .parents()

To get parents DOM element of elements, use the `.parents()` command.

    cy.get('.traversal-cite')
      .parents().should('match', 'blockquote')

> Lorem ipsum dolor sit amet, consectetur adipiscing elit.

#### .parentsUntil()

To get parents DOM element of elements until other element, use the `.parentsUntil()` command.

    cy.get('.clothes-nav')
      .find('.active')
      .parentsUntil('.clothes-nav')
      .should('have.length', 2)

#### .prev()

To get the previous sibling DOM element within elements, use the `.prev()` command.

    cy.get('.birds').find('.active')
      .prev().should('contain', 'Lorikeets')

- Cockatiels
- Lorikeets
- Cockatoos
- Conures
- Eclectus

#### .prevAll()

To get all previous sibling DOM elements within elements, use the `.prevAll()` command.

    cy.get('.fruits-list').find('.third')
      .prevAll().should('have.length', 2)

- apples
- oranges
- bananas
- pineapples
- grapes

#### .prevUntil()

To get all previous sibling DOM elements within elements until other element, use the `.prevUntil()` command.

    cy.get('.foods-list').find('#nuts')
      .prevUntil('#veggies').should('have.length', 3)

- Fruits
- apples
- oranges
- bananas
- Vegetables
- cucumbers
- carrots
- corn
- Nuts
- walnuts
- cashews
- almonds

#### .siblings()

To get all sibling DOM elements of elements, use the `.siblings()` command.

    cy.get('.traversal-pills .active')
      .siblings().should('have.length', 2)