gpt4 book ai didi

javascript - 如何使用 testcafe 获取表格所有单元格的文本

转载 作者:行者123 更新时间:2023-11-30 07:33:49 26 4
gpt4 key购买 nike

我正在使用 testcafe 测试框架 - https://devexpress.github.io/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 获取表格所有单元格的文本?

最佳答案

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

因此,使用以下解决方案:

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
}
}

请注意,Selector 从 v0.11.0 开始提供 'find' 和 'nth' 功能(它将很快发布,但它还可以使用 npm "alpha"标签)。

关于javascript - 如何使用 testcafe 获取表格所有单元格的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41018686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com