首页 > 解决方案 > 如何使用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 语句后验证它是否可用

标签: testingautomationautomated-testse2e-testingtestcafe

解决方案


在XpathSelector的帮助下,我们使用普通的 xpath 作为我们更喜欢在 selenium 中使用的方式。

定位器:

XPathSelector('//*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]')

为此,我们需要在我们的包中添加 XPathSelector.js。


推荐阅读