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?
Asked
Active
Viewed 143 times
0

Prophet
- 32,350
- 22
- 54
- 79
-
Yes, thanks to jrob. – Prophet Apr 25 '21 at 15:44
2 Answers
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
-
1This does not answer the question, but is suitable as a comment. – Greg Burghardt Apr 25 '21 at 15:43