Melab
Melab

Reputation: 2812

How can I use XPath to return a node that contains one particular element with particular inner text?

Let's say I want to find the <p> tag that ONLY contains <u>***</u>. What is the XPath query to use for this? I thought I found an answer in //p[u["..."]], but that does not work. This would be much easier if I could do something like //p[text()="<u>***</u>"].

Upvotes: 1

Views: 83

Answers (1)

Đỗ Quang Khải
Đỗ Quang Khải

Reputation: 77

In your case, <u> tag is child of <p>, so you can use: "/..". This syntax can select parent node of current node. Your xpath should be:

//p/u[text()="<yourtext>"]/..

You should refer to XPath Toturial on w3school for more syntax of XPath.

Upvotes: 1

Related Questions