如何在 Cypress 中点击 link?
How to click link in Cypress?
我想在包含其他几个 link 的页面中单击下方 link。
我尝试了 cy.get() 多种替代方法。我也试过 cy.contains('Content 6') 但收到错误。
<div class="column">
<a href="/admin/contents/109">
<div class="ui segment">
<div class="ui center aligned header">
Content 6
<div class="sub header">Add description to content packages
</div>
</div>
</div>
</a>
</div>
这是我的最终解决方案:
cy.get('a[href*="admin/contents"]').contains('Content 6').click()
在名为 Udo 的用户的帮助下,我在此页面上找到了解决方案:https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-get-an-element’s-text-contents
href 代码提供了更多有关如何处理此问题的示例,然后是针对同一问题的其他示例。
您必须 "get" 要单击的正确元素。在你的情况下,它可以这样处理:
// find the link with href attribute containing "admin/contents" and click it
cy.get('a[href*="admin/contents"]').click()
我想在包含其他几个 link 的页面中单击下方 link。 我尝试了 cy.get() 多种替代方法。我也试过 cy.contains('Content 6') 但收到错误。
<div class="column">
<a href="/admin/contents/109">
<div class="ui segment">
<div class="ui center aligned header">
Content 6
<div class="sub header">Add description to content packages
</div>
</div>
</div>
</a>
</div>
这是我的最终解决方案:
cy.get('a[href*="admin/contents"]').contains('Content 6').click()
在名为 Udo 的用户的帮助下,我在此页面上找到了解决方案:https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-get-an-element’s-text-contents
href 代码提供了更多有关如何处理此问题的示例,然后是针对同一问题的其他示例。
您必须 "get" 要单击的正确元素。在你的情况下,它可以这样处理:
// find the link with href attribute containing "admin/contents" and click it
cy.get('a[href*="admin/contents"]').click()