英文:
Cypress - Iterate over each element that takes to new page- perform some action on new page- Do this for all elements
问题
[![在此输入图像描述](https://i.stack.imgur.com/ZdGlH.png)](https://i.stack.imgur.com/ZdGlH.png)
[![在此输入图像描述](https://i.stack.imgur.com/U58Ic.png)](https://i.stack.imgur.com/U58Ic.png)
我在 Cypress 中遇到以下问题:
1. 获取所有删除按钮。
2. 遍历每个删除按钮。
3. 单击每个按钮。
4. 转到删除确认页面(它是完全不同的页面,而不是弹出窗口)
5. 单击(红色的)删除按钮(将返回到列表页面)
6. 对其余的购物清单执行相同的操作
```javascript
cy.get('a[href*=delete][href$=confirm]').each(($ele) => {
cy.wrap($ele).click({ force: true });
// 在确认删除屏幕上
cy.contains('button', 'Delete').click({ force: true });
});
英文:
I have below issue in cypress:
-
Get all delete buttons.
-
Iterate over each delete button.
-
click on each button.
-
Navigate to delete confirmation page(it is different page all together not a popup)
-
Click on (red) Delete button (will be navigated back to list page)
-
Perform same action on remaining shopping lists
cy.get('a[href*=delete][href$=confirm]').each(($ele) => { cy.wrap($ele).click({ force: true }); // on confirm delete screen cy.contains('button', 'Delete').click({force: true,});
答案1
得分: 1
尝试在循环内重复获取
const selector = 'a[href*=delete][href$=confirm]';
cy.get(selector).each(($el, index) => {
cy.get(selector).first()
.click({ force: true })
// 在确认删除屏幕上
cy.contains('button', 'Delete').click({force: true,})
cy.contains('h1', 'Name').should('be.visible') // 确认我们回到了第一页
})
英文:
Try repeating the get inside the loop
const selector = 'a[href*=delete][href$=confirm]'
cy.get(selector).each(($el, index) => {
cy.get(selector).first()
.click({ force: true })
// on confirm delete screen
cy.contains('button', 'Delete').click({force: true,})
cy.contains('h1', 'Name').should('be.visible') // confirm we are back on 1st page
})
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论