I am trying to get the xpath of a svg that has an attribute <use href= "#icon-map">
So far the path //*[local-name()='svg']/*[local-name()='use']
works, but it finds 84 entries.
How can I modify the xpath in order to select only the use that has the href as "#icon-map"
?
CodePudding user response:
You can use this:
//*[local-name()='svg'][use[@href="#icon-map"]]
or
//*[local-name()='svg'][*[local-name()='use'][@href="#icon-map"]]
See example.
If you have more results than you expect then you should use more specific paths to the element or take your query into (
..)
and add number of an item into [
..]
like :
(//*[local-name()='svg'][use[@href="#icon-map"]])[2]
CodePudding user response:
If use is an attribute
then you could do this :
//*[name()='svg']//*[@use and @href='#icon-map']
Also the above solution assumes that #icon-map
is unique in HTML DOM