# Traversal

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

#### cy.children()

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

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

#### cy.closest()

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

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

- 14 Events
- 54 Friends

#### cy.eq()

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

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

- tabby
- siamese
- persian
- sphynx
- burmese

#### cy.filter()

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

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

#### cy.find()

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

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

#### cy.first()

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

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

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

#### cy.last()

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

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

Link

#### cy.next()

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

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

- apples
- oranges
- bananas

#### cy.not()

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

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

#### cy.parent()

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

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

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

#### cy.parents()

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

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

> Lorem ipsum dolor sit amet, consectetur adipiscing elit.

#### cy.siblings()

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

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