How to verify text is present but only within a given DOM element?

I can use verifyTextPresent but that looks throughout the entire DOM. How do I limit the search to, for instance, a given div ?

I have some text which appears in multiple places and I want to be sure that the text I’m finding is the text I’m interested in .

I feel sure this must be a very common requirement but I can’t see it mentioned in the tuts etc.

Hi Richard,

you can use verifyElementVisible instead and you’ll be allowed to search in sub elements. Example:

String parentObjectPath = ".//div[1]/div/div/ng-view/div[4]/div/div[7]/div/div[2]/div"
String childObjectPath = "//div[text()='textYouLookFor']"

TestObject to = new TestObject().addProperty("xpath", ConditionType.EQUALS, parentObjectPath + childObjectPath)


Note double-slash at the beginning of child’s path, it means that you search only between child elements of a parent.


Excellent, thanks. I will try it out.