Creating XPATH for svg tag

2020-02-02 00:11发布

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>

3条回答
Explosion°爆炸
2楼-- · 2020-02-02 00: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

查看更多
Bombasti
3楼-- · 2020-02-02 00:20

Try the following xpath :

//svg[@class='svg-connector']
查看更多
Fickle 薄情
4楼-- · 2020-02-02 00:23

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

查看更多
登录 后发表回答