问题
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
andname()
://*[name()='svg']/*[name()='title']
Using
xpath
andlocal-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