Reading title tag in svg?

和自甴很熟 提交于 2021-02-10 05:19:30

问题


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:


To extract the text from the <title> tag within the svg 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:

  • How to click on SVG elements using XPath and Selenium WebDriver through Java
  • Unable to locate SVG elements through xpath on Kendo UI chart
  • Clicking on svg using selenium python


来源:https://stackoverflow.com/questions/63544775/reading-title-tag-in-svg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!