how to click the link in cypress

孤街浪徒 提交于 2020-01-15 15:32:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!