I tried to locate use element with attribute value '#aaa' for below snippet
<svg>
<use xlink:href='#aaa'></use>
</svg>
I was able to locate using css selector use[* |href='#aaa'] . But I require it in xpath. I tried below xpath but it is not working
(//*[name()='use'])[ * ='#aaa' or @href='#aaa']
Note :I need to use the value '#aaa' to differentiate from other elements.
Could anyone please help to construct this xpath.
Your predicate [ * ='#aaa' or @href='#aaa'] returns false as there is no attribute as href (but xlink:href), and use has no child nodes with text content '#aaa'.
Note that wild-card for any attribute is @* while just * is for any node (except attribute). Try below XPath
"//*[name()='use' and @*='#aaa']"
For XPath:
//*[name()='use'][contains(@*, '#aaa')]
Or variant provided by Andersson
Approaches with [@xlink:href='#aaa'] don't work on practice
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With