I need some clarification on the usage of Cypress. I'm writing some e2e tests and one of them failed, because the element is not visible.
I found this answer helpful, it solved my problem. Clicking element which is reported to be not visible.
cy.get('[data-cy="dApp Info"]').click({force: true});
But now I'm wondering about Cypress best practice.
For example, let's say I have a component, which I want to click. It's a link a
inside a div
, inside a div
, inside a nav
. (I gave the link the data-cy
property.) Even though as a user, the component is visible and clickable (see 1st image), the component is reported not to be visible (see 2nd image).
Is it best practice to add a data-cy
property to any element I want to click and just use .click({force: true})
or should I add a data-cy
property to one of the div
s which wrap my actual link and click those (is that even possible?)?
Edit
DOM Structure
<nav data-cy="sidebar-nav-studio">
<div>
<div>
<div>
<div>
<ul data-cy="dApp-sub-section-sidebar-nav-studio">
<span>
<a data-cy="Add Templates">
<div> </div>
<div>
<p>
Add Templates
</p>
</div>
</a>
<a data-cy="Look & Feel">
<div> </div>
<div>
<p>
Look & Feel
</p>
</div>
</a>
<a data-cy="dApp Info">
<div> </div>
<div>
<p>
dApp Info
</p>
</div>
</a>
</div>
</div>
</div>
</div>