Cypress - how to find by text content?

后端 未结 3 1828
面向向阳花
面向向阳花 2021-02-12 17:40

In Cypress, I want to select a button from a group of buttons based on its text-content. How can I do it? Here is my approach:

export const getCustomerButton = (         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 18:05

    Or maybe an even slicker solution is to use this:

    cy.contains('YOUR_BUTTON_CLASS', 'Customer');
    

    This can be done since contains() can hold 2 arguments. And if it gets two arguments the first one is always the element and the second the text.

提交回复
热议问题