Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JS Cypress finding row in table that contains value

I got table like this:

TABLE

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

Will this work if you just append the ID to your selector?

deleteRowByID(id){

    cy.get('nb-card-body').then(body =>{
        if(body.find('td:nth-child(2)').filter(":contains('" + id + "')").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)
        }
    })    
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading