I'm trying to open a link in the same tab using cypress
I tired using
cy.get('a').eq(0).invoke('removeAttr', 'target').click()
but it didn't work. after checking the HTML file I saw that there is no
target=_blank
att on the href
I cant understand why its opening on a new window and how to prevent it using cypress.
For a target=_blank anchor, you can either remove the target attribute or replace the _blank value with _self.
// remove attribute target
cy.get('a')
.eq(0)
.should('have.attr', 'target') // check it has target attr before removing
.invoke('removeAttribute', 'target')
.click()
// update target value
cy.get('a')
.eq(0)
.should('have.attr', 'targe', '_blank') // check target attr has _blank
.invoke('attr', 'target', '_self')
.click()