小编juv*_*uve的帖子

Cypress 迭代表行获取单元格中的特定元素

我试图迭代表行并获取包含特定值的每一行,但它对我不起作用。我用来.each()迭代行,并在其中的.within()每个行上$el使用,cy.get('td').eq(1).contains('hello')但我得到断言错误:

超时重试:期望在元素中找到内容:'hello':<td>但从未找到。

当我 console.log 时cy.get('td').eq(1),它会在每一行中生成所需的单元格并且测试通过,所以我不明白为什么链接.contains()不起作用......

it('get element in table', () => {
  cy.visit('http://localhost:3000/');
  cy.get('tbody tr').each(($el) => {
    cy.wrap($el).within(() => {
      cy.get('td').eq(1).contains('hello') // contains() doesn't work
    })
  })
});
Run Code Online (Sandbox Code Playgroud)
<table>
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>hello</td>
      <td>$80</td>
    </tr>
     <tr>
      <td>$10</td>
      <td>hello</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

javascript cypress

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

cypress ×1

javascript ×1