Checking for the existence of element


#1

Hello! Happy New Year!

I have a web site with one body tag with a number inside the tag. I need to ensure that body tag has something in it-- but we really don’t care what the number is. If the web site in question is broken, the body tag will be blank with no number. This is how the XPath selector is currently showing up:
/html/body[.=‘10.1.6.3’]

I really don’t care what the number is-- I just need to make sure something is there and not blank. How would you recommend we structure the test?


#2

Happy new year to you too, @micheleaz!

When you say a number inside the tag, you mean something like <body>10.1.6.3</body>?

If I understand your situation correctly, you could try building an xpath selector like /html/body and get the element’s text (d&d: Get > Element’s text).
Then assert that the text is not empty (or if you check for that specific number format, you could try Regex).

Hope this helps!