I am automating my regression checklist and I am stuck in a test case in which I have to test a link that opens in a new tab, as Cypress doesn't support multiple tabs, so I want to open that link in the same tab. The problem is the button doesn't contain any href link in tag. Here is the class.
Note: The code snips shown below are working fine if href exists.
<a rel="noopener noreferrer" target="_blank">
<div class="tooltip" style="width: fit-content;">
<span class="tooltip-trigger">
<button class="button-wrapper default undefined undefined mr-3">Preview</button>
</span>
</div>
</a>
I have tried multiple work around but nothing works for me. Some are as follow.
cy.xpath('/html/body/div[1]/div[1]/header/div[2]/a')
.should('have.attr', 'href').and('include', 'Preview')
.then((href) => {
cy.visit(href)
})
Another workaround.
cy.xpath("/html/body/div[1]/div[1]/header/div[2]/a")
.first()
.should(($a) => {
$a.attr("target", "_self");
}).click();
I tried this one too.
cy.xpath("/html/body/div[1]/div[1]/header/div[2]/a")
.invoke("removeAttr", "target")
.click();
Looking forward to hearing back from Community.