问题
How to click this link with cypress?
<a href="#" aria-disabled="false" class="button ">
<span class="icon icon-chevron-down " aria-hidden="true">
</span>
<span class="screen-reader-only">
chevron-down_icon
</span>
</a>
回答1:
That's pretty easy, the documentation of Cypress would help you as wel: https://docs.cypress.io/api/commands/click.html#Command-Log . But I'll help you too. I did the assumption that this is the only hyperlink on the page:
cy.get('a')
.click()
If it is not the only one you could try to get the link via the class (assuming that the class is unique on the page):
cy.get('.button')
.click()
If both assumptions are invalid, the class is not unique and there are multiple hyperlinks, you can try this:
cy.get('a')
.eq(1)
.click()
The 1 of eq() is the number of the element. The first element is 0, the second 1, the third 2, etc etc
Edit I saw you updated your original post, so I'll another option. You could use the other elements that are available:
cy.get('.icon-chevron-down')
.parent()
.click()
来源:https://stackoverflow.com/questions/56594334/how-to-click-the-link-in-cypress