https://cypress.io logo
I am not able to click on a link in table
# i-need-help
w
Below is the code snippet I am using. Please help pendingAuditsTable().within(() => { cy.get('tbody > tr > td:nth-child(1)').each(($elm, index, $list) => { const col = $elm.text(); cy.log(col); if (col.includes(facility)) { cy.log(facility); cy.get('tbody > tr > td:nth-child(1)').next().next().each(($el, index, $list) => { const col1 = $el.text(); if (col1.includes(audit_type)) { cy.log(col1) cy.get('tbody > tr > td:nth-child(1)').next() .next().next().next().next().next().invoke('text').then(text => { expect(text).to.include("Submitted"); if(text.includes("Submitted")){ cy.get('tbody > tr > td:nth-child(1)').next() .next().next().next().next().next().next().find('a') .eq(index).click(-25, 5, {force: true}); } }) return false; } }) return false; } })
e
HI @wide-eye-45012 Are you unable to click the link or is there a specific error message? At a high, glance your code is very hard to read due to the ton of nested conditionals. It's also difficult to understand what is happening without any context of your application or intentions. If your end intention is to click this line
cy.get('tbody  > tr > td:nth-child(1)').next() .next().next().next().next().next().next().find('a').eq(index).click(-25, 5, {force: true});
then there are plenty of reasons why this link couldn't being clicked (due to your conditionals and potential selectors). My only suggestion is to look into some selector best practices and see if you can simplify this greatly as this is going to be very hard to debug and understand long-term. I've also never had to provide an
x,y
value into a click so that could be causing problems as well but I don't know your specific use-case either.
w
Hi @enough-truck-68085 David, due to the way the table elements are rendered, I have to do the nesting as I am comparing the cell values and then getting the link. The logic works fine as I am able to identify the element but click() doesn't perform any action. I have given x,y because click() is pointing at the top right corner of the Edit link. I have tried both options with and without x,y without any success.
e
If the logic works for you than I don't know why it can't click without seeing more about the FE code. It's possible that the FE is re-rendering, preventing you from clicking. You can always try and validate the link is in the right state to be clicked first
cy.get('your-link').should('be.enabled').click()