如何使用 TestCafé 在 <br> 标记后为文本编写 xpath?
How to write xpath for text after <br> tag using TestCafé?
需要检查 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]
如何用文本('Contact')为这个元素编写xpath并在break语句后验证它是否可用
在 XpathSelector 的帮助下,我们使用普通的 xpath 作为我们更喜欢在 selenium 中使用的路径。
定位器:
XPathSelector('//*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]')
为此,我们需要在包中添加 XPathSelector.js。
需要检查 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]
如何用文本('Contact')为这个元素编写xpath并在break语句后验证它是否可用
在 XpathSelector 的帮助下,我们使用普通的 xpath 作为我们更喜欢在 selenium 中使用的路径。
定位器:
XPathSelector('//*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]')
为此,我们需要在包中添加 XPathSelector.js。