Reputation: 2690
<div>
<p>a</p>
<ul>
<li></li>
</ul>
<other-tags></other-tags>
<div>
I would like to select p
and li
tags in the above example.
I can do it using //div/p|//div/ul/li
, but is it possible to achieve the same without |
, in other words, not repeating //div
. I tried //div/*[self::p or self::ul/li]
, but it selected p
and ul
tags.
Upvotes: 1
Views: 125
Reputation: 44125
All you should do is use //p|//li
. Also, it helps to research stuff before
posting it on StackOverflow, as I found this information here. Why are you trying to avoid using |
in your XPath?
Upvotes: 0
Reputation: 111696
This XPath,
//*[self::p or self::li]
will select all p
and li
elements in the document.
This XPath,
//div[@id="i1"]//*[self::p or self::li]
will select all p
and li
elements under the targeted div
element(s).
Upvotes: 1