Creating XPATH for svg tag
Asked Answered
S

5

9

Below is the html for SVG, pls help me with creating XPATH for same

<svg data-reactid=".1q.0.3.1.0" version="1.1" class="svg-connector">
   <circle data-reactid=".1q.0.3.1.0.0" r="7" cy="11" cx="11" class="inner-circle"/>
</svg>
Stelle answered 28/2, 2018 at 7:24 Comment(0)
O
20

For svg nodes you need to use below syntax:

//*[name()="svg" and @class="svg-connector"]

This is because common HTML nodes and svg nodes belongs to different namespaces

Outbid answered 28/2, 2018 at 7:30 Comment(0)
S
10

The <svg> elements are not from the XHTML namespace but belongs to SVG namespace. Hence you have to specify name()="svg" while constructing the xpath as follows :

//*[name()="svg" and @class="svg-connector"]//*[name()="circle" and @class="inner-circle"]

You can find a detailed discussion in Selenium WebDriver [Java]: How to Click on elements within an SVG using XPath

Supervise answered 28/2, 2018 at 7:56 Comment(0)
C
1

Other suggestions didn't work for me. Here is what did:

//*[name() = 'svg'][contains(@class, 'input-class-name-here')]

Cote answered 16/11, 2021 at 8:10 Comment(0)
W
0

Try the following xpath :

//svg[@class='svg-connector']
Whisler answered 28/2, 2018 at 7:28 Comment(0)
E
0

This is like Andersson's suggestion, but seeks local-name nodes:

//*[local-name()='svg' and @class="input-class-name-here"]
Encore answered 27/5 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.