Cypress 获取table内容动态tr和td
时间:2022-07-22
本文章向大家介绍Cypress 获取table内容动态tr和td,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
前言
如何获取table内容动态tr和td的dom对象,今天给大家总结了方法。
获取table中DOM元素方法总结
<table id="projectstatus" class="sortable pane bigtable stripped-odd"><tbody><tr class="header"><th tooltip="上次构建状态" title="上次构建状态"><a href="#" class="sortheader"> S<span class="sortarrow"> </span></a></th><th tooltip="构建晴雨表" title="构建晴雨表"><a href="#" class="sortheader"> W<span class="sortarrow"> </span></a></th><th initialsortdir="down"><a href="#" class="sortheader">名称<span class="sortarrow"> ↓</span></a></th><th><a href="#" class="sortheader">上次成功<span class="sortarrow"> </span></a></th><th><a href="#" class="sortheader">上次失败<span class="sortarrow"> </span></a></th><th><a href="#" class="sortheader">上次持续时间<span class="sortarrow"> </span></a></th><th width="1"><a href="#" class="sortheader"> <span class="sortarrow"> </span></a></th><th><a href="#" class="sortheader"> <span class="sortarrow"> </span></a></th></tr><tr id="job_FCA玛莎拉蒂自动化测试" class=" job-status-blue"><td data="4"><img src="/static/ecc2f937/images/24x24/blue.png" alt="成功" tooltip="成功" style="width: 24px; height: 24px; " class="icon-blue icon-md" title="成功"></td><td data="100" class="healthReport" onmouseover="this.className='healthReport hover';return true;
" onmouseout="this.className='healthReport';return true;"><a href="job/FCA%E7%8E%9B%E8%8E%8E%E6%8B%89%E8%92%82%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/lastBuild" class="build-health-link"><img src="/static/ecc2f937/images/24x24/health-80plus.png" alt="100%" style="width: 24px; height: 24px; " class="icon-health-80plus icon-md"></a><div class="healthReportDetails"><table border="0"><thead><tr><th align="left">W</th><th align="left">描述</th><th align="right">%</th></tr></thead><tbody><tr><td align="left"><img src="/static/ecc2f937/images/16x16/health-80plus.png" style="width: 16px; height: 16px; " class="icon-health-80plus icon-sm"></td><td>构建稳定性: 最近没有失败的构建。</td><td align="right">100</td></tr></tbody></table></div></td><td><a href="job/FCA%E7%8E%9B%E8%8E%8E%E6%8B%89%E8%92%82%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/" class="model-link inside">1</a></td><td data="2020-07-17T02:00:14Z">
2 小时 56 分
- <a href="job/FCA%E7%8E%9B%E8%8E%8E%E6%8B%89%E8%92%82%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/lastSuccessfulBuild/" class="model-link inside">#26</a></td><td data="2020-07-15T01:48:39Z">
2 天 3 小时
- <a href="job/FCA%E7%8E%9B%E8%8E%8E%E6%8B%89%E8%92%82%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/lastFailedBuild/" class="model-link inside">#7</a></td><td data="1767243">29 分</td><td><a href="job/FCA%E7%8E%9B%E8%8E%8E%E6%8B%89%E8%92%82%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/build?delay=0sec"><img src="/static/ecc2f937/images/24x24/clock.png" onclick="return build_id2549(this)" alt="Schedule a 构建 for1" style="width: 24px; height: 24px; " title="Schedule a 构建 for FCA玛莎拉蒂自动化测试" class="icon-clock icon-md"></a><script>function build_id2549(img) {
new Ajax.Request(img.parentNode.href);
hoverNotification('构建 scheduled', img, -100);
return false;
}</script></td><td> </td></tr><tr id="job_2" class=" job-status-blue"><td data="4"><img src="/static/ecc2f937/images/24x24/blue.png" alt="成功" tooltip="成功" style="width: 24px; height: 24px; " class="icon-blue icon-md" title="成功"></td><td data="40" class="healthReport" onmouseover="this.className='healthReport hover';return true;
" onmouseout="this.className='healthReport';return true;"><a href="job/%E4%B8%80%E6%B1%BD%E6%95%B0%E6%8D%AE%E8%BF%90%E8%90%A5%E6%8E%A5%E5%8F%A3/lastBuild" class="build-health-link"><img src="/static/ecc2f937/images/24x24/health-20to39.png" alt="40%" style="width: 24px; height: 24px; " class="icon-health-20to39 icon-md"></a><div class="healthReportDetails"><table border="0"><thead><tr><th align="left">W</th><th align="left">描述</th><th align="right">%</th></tr></thead><tbody><tr><td align="left"><img src="/static/ecc2f937/images/16x16/health-20to39.png" style="width: 16px; height: 16px; " class="icon-health-20to39 icon-sm"></td><td>构建稳定性: 最近 5 次构建中有 3 次失败。</td><td align="right">40</td></tr></tbody></table></div></td><td><a href="job/%E4%B8%80%E6%B1%BD%E6%95%B0%E6%8D%AE%E8%BF%90%E8%90%A5%E6%8E%A5%E5%8F%A3/" class="model-link inside">2</a></td><td data="2020-06-12T02:16:03Z">
1 月 5 天
- <a href="job/%E4%B8%80%E6%B1%BD%E6%95%B0%E6%8D%AE%E8%BF%90%E8%90%A5%E6%8E%A5%E5%8F%A3/lastSuccessfulBuild/" class="model-link inside">#16</a></td><td data="2020-06-12T01:58:43Z">
1 月 5 天
- <a href="job/%E4%B8%80%E6%B1%BD%E6%95%B0%E6%8D%AE%E8%BF%90%E8%90%A5%E6%8E%A5%E5%8F%A3/lastFailedBuild/" class="model-link inside">#14</a></td><td data="18773">18 秒</td><td><a href="job/%E4%B8%80%E6%B1%BD%E6%95%B0%E6%8D%AE%E8%BF%90%E8%90%A5%E6%8E%A5%E5%8F%A3/build?delay=0sec"><img src="/static/ecc2f937/images/24x24/clock.png" onclick="return build_id2550(this)" alt="Schedule a 构建 for 一汽数据运营接口" style="width: 24px; height: 24px; " title="Schedule a 构建 for 一2" class="icon-clock icon-md"></a><script>function build_id2550(img) {
new Ajax.Request(img.parentNode.href);
hoverNotification('构建 scheduled', img, -100);
return false;
}</script></td><td> </td></tr><tr id="job_3" class=" job-status-blue"><td data="4"><img src="/static/ecc2f937/images/24x24/blue.png" alt="成功" tooltip="成功" style="width: 24px; height: 24px; " class="icon-blue icon-md" title="成功"></td><td data="100" class="healthReport" onmouseover="this.className='healthReport hover';return true;
" onmouseout="this.className='healthReport';return true;"><a href="job/%E9%95%BF%E5%9F%8E%E8%BD%A6%E4%B8%BB%E5%8D%A1%E4%B8%8A%E6%8A%A5%E6%A8%A1%E5%9D%97%E6%8E%A5%E5%8F%A3/lastBuild" class="build-health-link"><img src="/static/ecc2f937/images/24x24/health-80plus.png" alt="100%" style="width: 24px; height: 24px; " class="icon-health-80plus icon-md"></a><div class="healthReportDetails"><table border="0"><thead><tr><th align="left">W</th><th align="left">描述</th><th align="right">%</th></tr></thead><tbody><tr><td align="left"><img src="/static/ecc2f937/images/16x16/health-80plus.png" style="width: 16px; height: 16px; " class="icon-health-80plus icon-sm"></td><td>构建稳定性: 最近没有失败的构建。</td><td align="right">100</td></tr></tbody></table></div></td><td><a href="job/%E9%95%BF%E5%9F%8E%E8%BD%A6%E4%B8%BB%E5%8D%A1%E4%B8%8A%E6%8A%A5%E6%A8%A1%E5%9D%97%E6%8E%A5%E5%8F%A3/" class="model-link inside">3</a></td><td data="2020-07-17T02:30:49Z">
2 小时 25 分
- <a href="job/%E9%95%BF%E5%9F%8E%E8%BD%A6%E4%B8%BB%E5%8D%A1%E4%B8%8A%E6%8A%A5%E6%A8%A1%E5%9D%97%E6%8E%A5%E5%8F%A3/lastSuccessfulBuild/" class="model-link inside">#55</a></td><td data="2020-07-14T08:29:55Z">
2 天 20 小时
- <a href="job/%E9%95%BF%E5%9F%8E%E8%BD%A6%E4%B8%BB%E5%8D%A1%E4%B8%8A%E6%8A%A5%E6%A8%A1%E5%9D%97%E6%8E%A5%E5%8F%A3/lastFailedBuild/" class="model-link inside">#50</a></td><td data="26883">26 秒</td><td><a href="job/%E9%95%BF%E5%9F%8E%E8%BD%A6%E4%B8%BB%E5%8D%A1%E4%B8%8A%E6%8A%A5%E6%A8%A1%E5%9D%97%E6%8E%A5%E5%8F%A3/build?delay=0sec"><img src="/static/ecc2f937/images/24x24/clock.png" onclick="return build_id2551(this)" alt="Schedule a 构建 for 3" style="width: 24px; height: 24px; " title="Schedule a 构建 for3" class="icon-clock icon-md"></a><script>function build_id2551(img) {
new Ajax.Request(img.parentNode.href);
hoverNotification('构建 scheduled', img, -100);
return false;
}</script></td><td> </td></tr></tbody></table>
1.获取动态tr个数
describe('处理table方法总结', function () {
beforeEach(function () {
var username = "admin"
var password = ""
//登陆地址
cy.visit('http://xx.xx.xxx.xx:xxxx/login?from=%2F')
cy.get('#j_username').type(username)
cy.get('body > div > div > form > div:nth-child(2) > input').type(password)
cy.get('body > div > div > form > div.submit.formRow > input').click()
})
it('动态获取tr', function () {
cy.get('#projectstatus > tbody >tr').then(($el) => {
const tr_total = $el.length
cy.log(tr_total)
})
});})
2.获取动态tr去断言td内容
describe('处理table方法总结', function () {
beforeEach(function () {
var username = "admin"
var password = ""
//登陆地址
cy.visit('http://xx.xx.xxx.xx:xxxx/login?from=%2F')
cy.get('#j_username').type(username)
cy.get('body > div > div > form > div:nth-child(2) > input').type(password)
cy.get('body > div > div > form > div.submit.formRow > input').click()
})
it('动态获取tr', function () {
cy.get('#projectstatus > tbody >tr').then(($el) => {
const tr_total = $el.length
cy.log(tr_total)
var list =['29 分','18 秒',"26 秒"]
for (var i = 1; i < tr_total; i++) {
cy.get('#projectstatus > tbody >tr').eq(i).find('td:nth-child(6)')
.should('contain', list[i-1])
}
})
});})
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家的支持。
更多文章关注小编公众号:自动化测试 To share
- parcel和parcelable
- Windows Phone 7 WebBrowser 中文乱码问题
- Java并发包类总览
- 作业调度框架 Quartz.NET 2.0 beta 发布
- 系统捕获异常并发送到服务器
- 当调用GetAuthorizationGroups() 的错误-“试图访问卸载的应用程序域“(Exception from HRESULT: 0x80131014)解决方案
- WCF 4.0路由服务Routing Service
- ExpandableListView简单应用及listview模拟ExpandableListView
- 文件句柄与文件描述符
- android GifView分享
- VAE、GAN、Info-GAN:全解深度学习三大生成模型
- android获取设备唯一标示
- 如果正确读取SQL Server中的扩展事件?
- android自定义xmls文件属性
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 详解Linux中PostgreSQL和PostGIS的安装和使用
- 检测ip和port是否可连接的方法
- Linux关机时执行指定脚本功能实现
- 适用于稀疏的嵌入、独热编码数据的损失函数回顾和PyTorch实现
- CentOS7下实现终端输入中文设置详解
- CentOS 7.2搭建VNC远程桌面服务的方法
- Ubuntu挂载3T硬盘或大于2T磁盘的方法
- linux chroot命令详解
- Linux中如何查询运行文件的全路径的方法
- 基于可变自动编码器(VAE)的生成建模,理解可变自动编码器背后的原理
- Centos7上网及添加静态IP方法介绍
- 解决yum安装报错Protected multilib versions的问题
- Linux与Windows编码不一致的解决方案
- Linux运维之如何使用ss命令代替netstat
- 对Linux终端使用socks5代理的方法详解