typescript - 基于文本循环遍历 cypress 元素
问题描述
我要测试的页面有多个带有文本Order
的按钮。我正在尝试获取所有这些按钮并循环它们。
我不能使用cy.get('button).contains('Order')
,因为它只会返回第一个按钮。有没有办法做到这一点?
我什至试图循环所有按钮
cy.get('button').each(($button, index) => {
if ($button.text() == 'Order') {
cy.wrap($button).click();
}
});
但这会在第二个按钮上引发错误
cy.click() failed because this element is detached from the DOM.
任何帮助表示赞赏。
解决方案
推荐阅读
- c# - DropCreateDatabaseAlways - 删除数据库或架构?
- lua - 引用变量的Lua问题
- java - 从 Tomcat 7 迁移到 Tomcat 9,页面需要重新加载/刷新才能工作
- c# - Razor 运行时重新编译似乎不适用于 *.razor 组件文件
- unity3d - 如何为其他加入的玩家更改颜色?
- angular - 如何在打字稿中选择键值[object:object]?
- python - MyPy - 您如何在注释中实际使用类型化存根?
- xcode - 选中时如何使此按钮取消选中所有这些框?
- django - Django 在 URL 中访问 PK/Object
- javascript - javascript:每次点击函数时都覆盖设置间隔?