需要单击DIV以在柏树中自动化

发布于 2025-02-12 23:56:10 字数 1399 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

前事休说 2025-02-19 23:56:10

您可以按按钮的文字选择,

cy.contains('Upload in this folder').click()

You can select by the text of the button,

cy.contains('Upload in this folder').click()
偷得浮生 2025-02-19 23:56:10

您可以将选择器和内部文本的组合与一起使用

cy.contains('div', 'Upload in this folder').click()

You can use a combination of selector and inner text with contains for this.

cy.contains('div', 'Upload in this folder').click()
¢好甜 2025-02-19 23:56:10

由于这是模态以模态出现的按钮,因此您需要在模态DOM元素中进行搜索,因此您可以抓住正确的DOM,而不是DOM中存在的另一个元素。

我们将我们功能强大的 .contains() 以正则态度作为参数,因为添加选择器可以使其更脆弱。

注意:我看不到您的模态HTML,因此我将在下面的示例中使用虚拟选择器。

// 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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文