testing - 如何使用TestCafé在<br>标签之后为文本编写xpath?
问题描述
需要检查break(br)标签后的文本是否可用
HTML 代码:
<div class="a-column a-span3">
<a class="footer-link" target="_blank" rel="noopener" href="https://www.community.com/">
<span class="footer"><b>Community</b></span>
<br>
Connect
<br>and fun
</a>
</div>
<div class="a-column a-span3">
<a class="footer-link" target="_blank" rel="noopener" href="https://www.google.com/">
<span class="footer"><b>google</b></span>
<br>
Contact
<br>and get help
</a>
</div>
我试过了,错误是:
1) AssertionError: expected false to be truthy
48 | async checkFooter(footerText){
> 49 | await t.expect((Selector('[id=container]').child('div').nth(14).child('div').nth(5).child('div').child('div').nth(2).child('a').withText(footerText)).exists).ok();
50 | }
普通 Xpath://*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]
如何使用 text('Contact') 为该元素编写 xpath 并在 break 语句后验证它是否可用
解决方案
在XpathSelector的帮助下,我们使用普通的 xpath 作为我们更喜欢在 selenium 中使用的方式。
定位器:
XPathSelector('//*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]')
为此,我们需要在我们的包中添加 XPathSelector.js。
推荐阅读
- regex - 正则表达式:匹配等号前括号之间的所有字符
- vue.js - 离子电容器 + vue 网络错误“Android 模拟器上 XMLHttpRequest.m.onabort 的 e.exports (chunk-vendors.85bc3696.js:1) 中的请求中止”
- python - pySpark:将 Kafka 流放入 parquet 并从远程会话中读取 parquet
- javascript - Mongoose/MongoDB GeoJSON 查询返回空结果
- php - Wordpress:显示与 2 个术语相关的项目
- nearprotocol - Near Explorer block query starts from 9820221
- docker - 在 windows 容器中,如何优雅地关闭 asp.net core 应用程序?
- python - 为什么lambdify永远不会停止?
- jquery - 将选择更改为他的下一个值
- git - 让 git 在不覆盖现有代码的情况下进行更改