SVG Elements
Learn how to locate and interact with SVG elements used in modern dashboards, charts, icons and graphical interfaces.
What You Will Practice
- Understand SVG elements.
- Locate SVG using XPath.
- Locate SVG using CSS selectors.
- Work with SVG path elements.
- Click SVG icons.
- Identify SVG attributes.
- Work with SVG charts.
- Practice real Selenium scenarios.
SVG Icon
Locate and click an SVG icon.
//button[@id='searchSvgButton']//*[name()='svg']
CSS
#searchSvgButton svg
SVG Path
Identify an SVG path using the name() function.
//*[name()='path' and @id='targetSvgPath']
SVG Button
Click a button containing an SVG graphic.
//button[@id='downloadSvgButton']
SVG Chart
Practice locating graphical elements inside an SVG chart.
//*[name()='circle' and @data-month='June']
SVG Attributes
Read SVG attributes such as viewBox and data values.
element.getAttribute("viewBox");
element.getAttribute("data-chart");
Real-World SVG Search
Locate an SVG icon using its accessible label.
//button[@aria-label='Notifications']//*[name()='svg']
SVG Selenium Cheat Sheet
//*[name()='svg']
//*[name()='path']
//*[name()='circle']
//*[name()='circle'] [@data-month='June']
button svg
driver.findElement(
By.xpath(
"//*[name()='svg']"
)
);