I want to take the last row in the third column in my dynamic table.This cell has the last email randomly created and stored in the variable storedEmail. Those are what I tried:
cy.fixture('email.json').then((fixture) => {
const storedEmail = fixture.email;
cy.get('table')
.find('tr')
.last()
.find('td:nth-child(3)')
.invoke('text')
.then((cellText) => {
expect(cellText.trim()).to.contain(storedEmail);
});
});
});
I also tried:
cy.get('table')
.find('tbody > tr')
.last()
.within(() => {
cy.get('td:nth-child(3)')
.invoke('text')
.then((cellText) => {
const trimmedText = cellText.trim();
cy.log('Cell Value:', trimmedText);
expect(cellText.trim()).to.contain(storedEmail);
});
});
But both snippets gave me the first row instead the last one.