javascript - 表元素断言
问题描述
我试图断言 11223 是否显示在桌子上。
元素如下:
<div class="page-wrapper table-responsive" id="shipping-option" xpath="1">
<table class="table table-bordered">
<tbody>
<tr>
<th></th>
<th class="checkUncheck">
<span title="" data-toggle="tooltip" data-placement="top" data-original-title="Check / Uncheck All">
<input type="checkbox" id="checkAll" class="icheckbox_square-green form-control">
</span>
</th>
<th>
Date/ID
</th>
<th>
Name(pet name)
</th>
<th>
Country/State
</th>
<th>
Designation
</th>
</tr>
<tr class="rowclick" style="cursor:pointer">
<td>
1
</td>
<td class="shipmentCheckbox">
<input class="GroupChb" id="61577" name="item.isSelected" type="checkbox" value="true"><input name="item.isSelected" type="hidden" value="false">
</td>
<td>
06-01-2021
<br>
<a href="http://www.google.dk" target="popup" onclick="window.open('http://www.google.dk'),'popup','width=600,height =600'); return false;">
11223
</a>
</td>
<td>
Jonny
<br>
<span class="sub">
Joe
</span>
</td>
<td>
US <br>
<span class="sub">California</span>
</td>
<td>
Software Quality Analyst
<br>
<span class="sub">
QA
</span>
</td>
</tr>
<tr>
<td colspan="10"></td>
</tr>
</tbody>
</table>
<div>
这是行不通的。我收到以下错误:
-包含 tr.rowclick,11223
重试超时:预计在元素中找到内容:“11223”:<table.table.table-bordered> 并使用选择器:“tr.rowclick”,但从未找到。赛普拉斯/集成/History.js:55:65 53 |
cy.get('#SearchString').type('11223') 54 | cy.get('#filter').click() > 55 | cy.get('.page-wrapper').find('.table-bordered').contains('tr.rowclick','11223') | ^ 56 | 57 | }) 58 | })
解决方案
<td>
没有 rowclick 类,有<tr>
它。
这是我检查“11223”是否在单元格中的首选命令:
cy.contains('tr.rowclick td', '11223')
请注意,将搜索所有<td>
子元素(如<a>
)。
这是我喜欢的一种极简主义方法,因为对页面结构的更改可能会破坏测试(个人偏好)。
推荐阅读
- ios - 如何使用 XCUITest 测试 UIImageView 是否包含具有特定名称的图像?
- typescript - 在函数中定义接口
- c - gprof 输出显示不存在的调用图边缘
- ruby-on-rails - Rails 与多态性和抽象类的关联
- javascript - 访问不在数组中的 json 子对象
- for-loop - 在 kotlin 中替换用于搜索列表的 for 循环
- mysql - 在 SQL 中每天计算用户匹配次数
- nuxt.js - 为什么 nuxt 构建的应用程序中的 baseURL 总是像服务器应用程序的 baseURL?
- c++ - constexpr 和 std::cout 处理函数但不在 lambda 中
- node.js - Mongoose 模式实例方法不是函数