WebTable Handling:

Getting the table header cell elements

To get access to the table header cells, this is used as a CSS.

cy.get("th")    //selects the table header elements

Accessing the Rows and Column elements

To get access to the row and column elements, tr and td (or) tr td is used as a CSS.

hello.js
cy.get("tr")        //selects the row elements
cy.get("td")        //selects the columns elements
cy.get("tr td")     //selects the columns elements

Accessing the Specific web table elements with assertions

With the help of the :nth-child concept in css, we can identify all the values of a particular column.

cy.visit("https://www.seleniumeasy.com/test/table-search-filter-demo.html")
cy.get("tr td:nth-child(2)")     //Gets the 2nd child in td column
  .eq(1)                         //Yields second matching css element 
  .contains("sometext")
  .should('be.visible')

Accessing the web table elements with text

.each() the method is used to iterate the elements in an array. Here we are iterating through the second column elements such that it matches the given text.

Example: Let's consider this table

Accessing the Siblings web table elements with elements found

Retrieving a value from a table cell appearing in the next or previous column of the same row. In Cypress, we have the command .next() & .prev() to move to the immediate following or preceding sibling in DOM respectively. Note: The .next() & .prev() command works only if it is chained with the cy.get() command.

Example: .next() command

Example: .prev() command

Last updated

Was this helpful?