Javascript 在Cypress中,如何计算表中的行数?

Javascript 在Cypress中,如何计算表中的行数?,javascript,laravel,cypress,web-component-tester,Javascript,Laravel,Cypress,Web Component Tester,我正在用cypress做E2E测试。 我必须计算表中的行数,每种情况都不同 在普通javascript中,我编写此代码只是为了获得列的总行数 document.getElementById('hometable').getElementsByTagName("tr").length-1 不幸的是,在cypress中,我遇到了以下错误: document.getElementById('hometable').getElementsByTagName("tr&qu

我正在用cypress做E2E测试。 我必须计算表中的行数,每种情况都不同

在普通javascript中,我编写此代码只是为了获得列的总行数

document.getElementById('hometable').getElementsByTagName("tr").length-1
不幸的是,在cypress中,我遇到了以下错误:

 document.getElementById('hometable').getElementsByTagName("tr").length-1

VM298:1 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
    at <anonymous>:1:38
(anonymous) @ VM298:1

我不知道它在哪里返回我的行数

我认为您的方法是正确的,您可以使用
each()
。您还可以向每个列表添加一个参数,列表,这将为您提供行数计数。你可以查一下电话号码。确保定位器正确无误

cy.get('#hometable > tr').each(function(row, i, list) {}).then(function(list) {
      //list will give you the count of tr
    }

我认为您的方法是正确的,您可以使用
each()
。您还可以向每个列表添加一个参数,列表,这将为您提供行数计数。你可以查一下电话号码。确保定位器正确无误

cy.get('#hometable > tr').each(function(row, i, list) {}).then(function(list) {
      //list will give you the count of tr
    }
这回答了你的问题吗?这回答了你的问题吗?