XPath to pick an element based on the text in parent or any of its child
XPath to pick an element based on the text in parent or any of its child Is there a way to pick an element if that element or any one of the child has a particular text? For example, Here are two examples: Example 1: <div title='Title1'> <input type='checkbox'> "Tag 1" </div> Example 2: <div title='Title2'> <input type='checkbox'> <span>Tag 1<span> </div> I want to pick tag div regardless if the text is inside the span or not. But the below XPath picks the tag span for the second case. //*[(contains(text(), 'Tag 1'))] Is there any better XPath to pick the div based on the text inside the parent or any of the child? 1 Answer 1 Is there any better XPath to pick the div based on the text inside the parent or any of the child? Use . , not text() . . text() //*[contains(., 'Tag 1')] text() d...