1

Need to check the text is available after break(br) tag

HTML code:

<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>

I tried and got the error is:

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 |    }

Normal Xpath: //*[@id="container"]/div[14]/div[5]/div/div[2]/a/text()[1]

How to write xpath for this element with text('Contact') and verify it is available after the break statement

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • I'm not sure to fully understand your need. In your sample data, you have to check if "Contact" exists after the br tag ? If that's the case, `normalize-space(//div[2]//br[1]/following::text()[1])="Contact"` will return True/False to check this condition. – E.Wiest Apr 05 '20 at 02:54
  • Thanks @E.Wiest for trying to help. But it is not I'm expecting. I need the xpath in testcafe format – gomathi subramanian Apr 05 '20 at 03:05
  • Use the [xpath-to-css](https://www.npmjs.com/package/xpath-to-css) package as suggested in the [How to write xpath with contains ID using TestCafé?](https://stackoverflow.com/questions/60911169/how-to-write-xpath-with-contains-id-using-testcaf%C3%A9) thread. – Alex Skorkin Apr 06 '20 at 14:14
  • xpath-to-css is not helpful in this instance, but [XpathSelector](https://github.com/DevExpress/testcafe-examples/tree/master/examples/use-xpath-selectors) really helps in my project. It really works – gomathi subramanian Apr 08 '20 at 11:23

1 Answers1

2

With the help of XpathSelector, we use the normal xpath as what we prefer to use in selenium.

Locator:

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

For this we need to add XPathSelector.js in our package.