// made up modal selector
cy.get('.modal')
// always good to assert the modal should be visible
.should('be.visible')
.contains(/upload in this folder/i)
// make sure it is visible before clicking
.should('be.visible')
.click()
Since this is button appears in a modal, you'll want search within the modal DOM element so you grab the correct one and not another one that exists in the DOM.
We will us the powerful .contains() with a regex as an argument since adding a selector could make it more brittle.
NOTE: I don't see html for your modal so I will use a dummy selector for it in the example below.
// made up modal selector
cy.get('.modal')
// always good to assert the modal should be visible
.should('be.visible')
.contains(/upload in this folder/i)
// make sure it is visible before clicking
.should('be.visible')
.click()
发布评论
评论(3)
您可以按按钮的文字选择,
You can select by the text of the button,
您可以将选择器和内部文本的组合与
一起使用
。You can use a combination of selector and inner text with
contains
for this.由于这是模态以模态出现的按钮,因此您需要在模态DOM元素中进行搜索,因此您可以抓住正确的DOM,而不是DOM中存在的另一个元素。
我们将我们功能强大的
.contains()
以正则态度作为参数,因为添加选择器可以使其更脆弱。注意:我看不到您的模态HTML,因此我将在下面的示例中使用虚拟选择器。
Since this is button appears in a modal, you'll want search within the modal DOM element so you grab the correct one and not another one that exists in the DOM.
We will us the powerful
.contains()
with a regex as an argument since adding a selector could make it more brittle.NOTE: I don't see html for your modal so I will use a dummy selector for it in the example below.