首页 > 解决方案 > 如何单击柏树中所选元素中的子元素?

问题描述

我有行(列表)的表。我使用 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>

如何单击所选元素中的子元素?

标签: cypress

解决方案


一种替代方法是使用find()

cy.get("tr:contains('testName12')", { timeout:20000}).find('.anticon-delete').click({force: true})

推荐阅读