如何通过按钮上的文本在柏树中找到并单击按钮元素

How can I find and click button element in cypress by the text on the button

我无法找到使用 cypress 定位此元素的方法。我不想使用 class 这个名字,因为它很复杂,我想使用“支持”来保持我的代码干净。

<button type="button" class="border-secondary shadow-none btn btn-outline-primary">Support</button>

我已经尝试 cy.get('button').contains('Support').click() 但没有成功。

.contains() 的另一种变体只会为您提供“支持”按钮

cy.contains('button', 'Support')