0

我使用testcafe测试框架得到表的所有单元格的文本 - https://devexpress.github.io/testcafe
我写了下面的代码:我如何可以用testcafe

const table = Selector('#table'); 

for(let i = 0; i < table.rows.length; i++){ 
    for(let j = 0; j < table.columns.length; j++) { 
     let tdText = await table.rows[i].cells[j].textContent; 
     //another actions 
    } 
} 

我如何能得到使用testcafe表的所有单元格的文本?

+0

'让I'大概应该是'让i'和'table.rows.lenght'大概应该是'table.rows.length'。 – RobG

+0

好的。我更新了代码示例。它仍然不起作用。 – mlosev

回答

0

选择器提供的方法和属性来选择页面上的元素,并得到他们的状态,但没有“行”和“列”的性质。

因此,采用如下方案:

const table  = Selector('#table'); 
const rowCount = await table.find('tr').count; 
const columnCount = await table.find('tr').nth(0).find('td').count; 

for(let i = 0; i < rowCount; i++) { 
    for(let j = 0; j < columnCount; j++) { 
     let tdText = await table.find('tr').nth(i).find('td').nth(j).textContent; 
     //another actions 
    } 
} 

注意选择器提供“发现”,由于v0.11.0“第n个”功能(它会很快被释放,但它的产品尚未与故宫“阿尔法”标签)。

0

你需要所有文字内容吗?在这种情况下,你可以使用ClientFunction

import { ClientFunction } from 'testcafe'; 

const getInnerText = ClientFunction(() => document.getElementById('table').innerText); 

const text = await getInnerText();