cypress - 如何单击柏树中所选元素中的子元素?
问题描述
我有行(列表)的表。我使用 get 获取元素并单击它。
HTML:
<table>
<tbody>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr data-row-key="5fc63ee4502a5d60c8fc9550">
<td>43</td>
<td>testName12</td>
<td>
<div>
<button type="button">
<i aria-label="icon: edit" class="anticon-edit"></i>
</button>
<button type="button">
<i aria-label="icon: delete" class="anticon-delete"></i>
</button>
</div>
</td>
</tr>
</tbody>
</table>
这条线是为我选择的,一切都很好:
cy.get("tr:contains('testName12')", { timeout:20000}).click({force: true})
但是在这个元素中,我有相同的孩子('按钮'),我需要点击其中一个:
cy.get("tr:contains('testName12')", { timeout:20000}).children('.anticon-delete').click({force: true})
我收到一个错误:
Timed out retrying: Expected to find element: .anticon-delete, but never found it. Queried from element: <tr.ant-table-row.ant-table-row-level-0>
如何单击所选元素中的子元素?
解决方案
一种替代方法是使用find()
cy.get("tr:contains('testName12')", { timeout:20000}).find('.anticon-delete').click({force: true})
推荐阅读
- javascript - 使用 `fetch` 或 `request` 发送 multipart/form-data 的正确方法
- javascript - JavaScript 中动态创建的文件列表
- c# - EF Core - 转换为 SQL 简单选择
- c# - 当打印输入流真的很大时,如何避免自动清除控制台?
- php - how to break password hash security
- html - 带有媒体查询的时事通讯
- javascript - 字符串枚举键索引对象的打字稿定义?
- php - 性能 / 练习 PHP & Eloquent
- wordpress - Wordpress 网站未加载并显示加载图标
- python - Python 键盘库“参数 1 必须是字符串而不是 unicode”错误