0

On this page there is a chart.
Here I can only locate the chart boundaries element //div[@data-chart_id='product_cannabinoids'] however I'm not able to locate the rect, svg or g elements inside it.
I see all these elements in the F12 but nothing like //div[@data-chart_id='product_cannabinoids']//svg or //div[@data-chart_id='product_cannabinoids']//rect gives any much.
I guess it's some kind of JavaScript dynamic elements, but still, these are not pseudo elements. They are looking like regular elements!
So why this happens and how can we locate these elements with Selenium?

Prophet
  • 32,350
  • 22
  • 54
  • 79

2 Answers2

1

XPATH requires a different way of finding 'svg' and 'rect' elements, using this syntax will work -

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

this is caused because 'svg' and 'rect' use different XML namespaces.

An alternative is using css selectors, css works normally with all type of elements.

amitlisha
  • 140
  • 1
  • 8
0

From my understanding, SVG elements aren't the same as normal elements and can be a little tricky.

Check out this response:

Selenium WebDriver: clicking on elements within an SVG using XPath

jrob11
  • 315
  • 1
  • 9