Basically I want to check if the element exists in the iframe. I am using cypress-iframe package for accessing elements in iframe. I searched a alot but I couldn't find any working answer. all the answers are about cypress itself but when it comes to iframe the solutions are not working. Example if the button exists in the iframe i want to click. If doesn't exist I want to continue with the other steps.
The error i get is cypress can't find the element. I tried with get function, it is the same. cypress tries to find the element and gives error because it doesn't find. But i want to know if exists and then take action.
cy.enter('.my-iframe').then(frameBody => {
// This is not working
if(frameBody().find(".my-button").length > 0){
frameBody().find(".my-button").click();
}
});
<iframe class="my-iframe" src="content.html" style="height:200px;width:300px"></iframe>