Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium/java-xpath for xlink:href attribute

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.

like image 621
testXXX Avatar asked Sep 03 '26 07:09

testXXX


2 Answers

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']"
like image 106
Andersson Avatar answered Sep 04 '26 22:09

Andersson


For XPath:

//*[name()='use'][contains(@*, '#aaa')]

Or variant provided by Andersson

Approaches with [@xlink:href='#aaa'] don't work on practice

like image 24
Aleh Baslak Avatar answered Sep 04 '26 22:09

Aleh Baslak