-1

Lets say my website contains multiple svg elements and I want to find the following:

<svg id="some-svg-id" />

How can I find this svg via its id?

I aware that //*[local-name()='svg'] finds all svg elements but how can I narrow it further down to one specific via its id?

Dev97M
  • 45
  • 5
  • Does this answer your question? [XPath with multiple conditions](https://stackoverflow.com/questions/10247978/xpath-with-multiple-conditions) – JaSON May 06 '21 at 15:16

2 Answers2

0

Try this one

//svg[@id='some-svg-id']

or, since id should be unique, this one:

//*[@id='some-svg-id']
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • Thanks but that only displays the symbol in the list of the svg imports on the html and not the physical location of my specifc svg – Dev97M May 06 '21 at 08:53
  • 1
    I'm not sure what you mean. What does it mean you need the 'physical location' of the svg? – Mate Mrše May 06 '21 at 08:55
  • I want to locate the exact place of one specific svg on the html as an Element and not its "import statement" – Dev97M May 06 '21 at 09:04
0

Hi you can use below solution to fix your problem:

//[name()='svg']//[local-name()='g' and @class='your-class-name']

or

//[name()='svg']//[local-name()='g' and @class='your-class-name']//*[text='rect']

Use * after // something like : //*

Shivu B Sasanur
  • 109
  • 1
  • 5