Xpath: How to search in all child elements with certain text (browser validation tool)
I have a number of p elements in a div and I want to find a certain text within all of them. For some reason I can't get it to work, it finds only the first p element. Does any one know what to use differently?
Element property: I've tried both text and value here (with and without [1] )
Xpath: /descendant::div[@class="Example1"]//*
I have also tried Xpath: /descendant::div[@class="Example1"]//p
I have added a jpg because apparently I can't add this directly here as text.
Comments
-
Assuming this is the first instance of the text "Text to find" on you page in a P element and you are looking for exactly the phrase "Text to find," you could use an "Element properties" locator like:
Element name: p
Attribute name: text
Attribute valueL Text to findIf you prefer using an XPath, it would be:
/descendant::p[normalize-space(.)="Text to find"]
If you must find the text within the div, or if there might be other text within the P element to find, an XPath like the following should work:
/descendant::div[@class="Example 1"]//p[contains(text(), "Text to find")]
for example:
/descendant::div[@class="Message userContent"]//p[contains(text(), "tried both")]
will select the second paragraph in your post on this page.1 -
Thank you very much! The second one worked for me.
0