I have the following XPath expression:
//a[@attribute='my-attribute']
When I have the following element in the HTML that XPath is searching, it matches as expected:
<a attribute="my-attribute">Some text</a>
But if there is an <svg>
tag under that element, XPath returns no match:
<a attribute="my-attribute">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"
viewBox="0 0 24 24" focusable="false"></svg>
</a>
Why doesn't XPath match in this case? Is there a way I can modify my expression to make it match?
EDIT:
Apparently it has to do with the namespace on the <svg>
element. Using the local-name()
function makes it match in the XPath tester I'm using:
//*[local-name()='a' and @attribute='my-attribute']
However, this still doesn't match when running through Selenium WebDriver. Any idea of how to get this working with Selenium?