Find element contains specific "path" attribute


Can someone please assist with the following issue?

I have map with more than 2000 elements loaded, but only one of them (which is currently visible) has the element ‘path‘ with an attribute d different than zero. For easier understanding, refer to the following screenshot:

enter image description here

Tried with this: SVG & Path finding, but did not find what I was looking for.

And having this XPath:

//div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and @d="M0 0"]

which finds all of them (2000).

What I am looking for is something like this (though I could not find the correct solution) – deliberately just added end of Xpath.

In summary, I need the d attribute (inside path) to not contain the value zero:

//*[name()='svg']//*[name()='path' and @d(contains,"125")]

Please assist, and thank you in advance.


According to your descriptions you are looking for locator where d attribute value is not equals to M0 0.
This can be translated to XPath with not operator.
Please try this:

//div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and(not(@d="M0 0"))]

Answered By – Prophet

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published