【问题标题】:How to click an element of a table row that has a column with specific text?如何单击具有特定文本列的表格行的元素?
【发布时间】:2019-06-02 13:49:27
【问题描述】:

我有一个包含多行的表。我需要能够找到具有特定文本的列,然后单击该行的删除按钮。

我可以通过它的用户名找到该行,但是当我尝试说“单击它的删除按钮”时,它抱怨它找不到删除按钮的元素。

表格代码:

<tbody>
    <tr>
        <td class="align-middle">77716d61-32ea-4bf3-a2bd-e48645d049ee</td>
        <td class="align-middle">asdf</td>
        <td class="align-middle">asdf@asdf.com</td>
        <td class="align-middle">
            <a class="btn btn-danger" href="/Identity/UserDelete/77716d61-32ea-4bf3-a2bd-e48645d049ee"><span class="oi oi-x"></span></a>
        </td>
</tbody>

我试过了:

.click(Selector('tbody').find('td').withText(name).find('.btn.btn-danger'))

和:

.click(Selector('tbody').find('td').withText(name).find('td').find('a').find('.btn.btn-danger'))

还和兄弟姐妹一起玩,但我不太明白。

预期:为该表的行单击删除按钮。

实际: 在找到具有 UserName 的列后,它不想继续遍历该行来单击删除按钮。

The specified selector does not match any element in the DOM tree.

   | Selector('tbody')
   |   .find('td')
   |   .withText('Automationieweg')
 > |   .find('td')
   |   .find('a')
   |   .find('.btn.btn-danger')

【问题讨论】:

标签: javascript automated-tests e2e-testing web-testing testcafe


【解决方案1】:

我更仔细地研究了 testcafe 的 .sibling 并提出了这个解决方案:

.click(Selector('tbody').find('td').withText(name).sibling('td').find('a').nth(1))

这会找到我要查找的名称的行,从具有“a”子元素的父“tr”获取“td”的兄弟元素,然后单击该行中的第二个元素(即删除按钮。)

【讨论】:

    【解决方案2】:

    当你得到你的用户名元素时,你必须找到带有删除按钮的公共父元素并在父元素中找到它。这在javascript中很容易

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 2020-01-28
      • 2017-03-03
      相关资源
      最近更新 更多