Verdouze
Verdouze

Reputation: 467

How to test values in second table with Cypress

I'm currently trying to get the length of the second table of my web page.

I have the impression that you can't do two "get" in the same line (as you can see below).

cy.get('table').eq(1).get('tbody>tr').its('length').should('be.gt', 1)

So my approach is to access the second table from where the".eq(1)", and to do a get from behind to get my lines back.

enter image description here

This is what the page looks like, and the highlighted line is the table I want to test.

Thank you for your answers.

Upvotes: 1

Views: 1050

Answers (1)

CD..
CD..

Reputation: 74166

You can use within:

Scopes all subsequent cy commands to within this element.

For example:

cy.get('table').eq(1).within(() => {
  cy.get('tbody>tr').its('length').should('be.gt', 1)
})

Upvotes: 3

Related Questions