Reading title tag in svg?

Viewed 720

How do I read the text in below? svg seems to be a special case.

Tried the below, but of no help

//*[name()='svg']/title

//*[name()='svg' and @title='Test']

//*[name()='svg' and contains(@title,'Test')]

    <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 137 125" version="1.1">
        <title>Test</title>
        <desc>Created with Sketch.</desc>
1 Answers

To extract the text from the <title> tag within the WebElement you can use either of the following Locator Strategies:

  • Using css_selector:

    svg>title
    
  • Using xpath and name():

    //*[name()='svg']/*[name()='title']
    
  • Using xpath and local-name():

    //*[local-name()='svg']/*[local-name()='title']
    

Reference

You can find a couple of relevant discussions in:

Related