I got table like this:
Im trying to write a function that will go thru pages of the table to find row with ID that i passed, and then delete this row.
My function looks like this:
deleteRowByID(id){
cy.get('nb-card-body').then(body =>{
if(body.find('td:nth-child(2)').filter(":contains('15')").length > 0){
cy.contains('td:nth-child(2)',id).parent('tr').find('.nb-trash').click()
} else {
cy.get('[aria-label="Next"]').click()
this.deleteRowByID(id)
}
})
}
if(body.find(‘td:nth-child(2)’).filter(":contains(’15’)").length > 0) – im getting column with ID’s from the table and then i check if there is value that im looking for on this page of table.
In IF statement there is hard-coded ’15’ value. If i switch it to variable "id" it wont work since it will look for value = "id" instead of the variable value that i passed.
How can i fix it?
2
Answers
Can i also somehow use .includes instead of .filter and use the "textContent" value of each object??
The cy.log(body.find('td:nth-child(2)')) output looks like this
Will this work if you just append the ID to your selector?