How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
问题描述
我使用 testcafe
测试框架 - https://devexpress.github.io/testcafe.
我写了以下代码:
I using the testcafe
testing framework - https://devexpress.github.io/testcafe.
I wrote the following code:
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 获取表格中所有单元格的文本?
How do I can get a text of all the cells of the table using testcafe?
推荐答案
Selector 提供方法和属性来选择页面上的元素并获取它们的状态,但没有行"和列"属性.
Selector provides methods and properties to select elements on the page and get theirs state, but has no 'rows' and 'columns' properties.
所以,请使用以下解决方案:
So, use the following solution:
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" 标记使用).
Note that Selector provides 'find' and 'nth' functions since v0.11.0 (it will be released soon, but it's available yet with npm "alpha" tag).
这篇关于如何使用 testcafe 获取表格中所有单元格的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 testcafe 获取表格中所有单元格的文本


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01