Having trouble using an xpath for svg

Hi,

Im trying to use an xpath=//svg which I can see on the inspect tool but when I run it in robotframework to check if its visible it tells me that it cant find the xpath.

This is for a “highcharts-series-group” if that helps

Is there a certain way you need to use an xpath locator for these things?
Ive got waits in which are more than enough for it to load but still doesnt work

It’s possible that the XPath you’re using is not specific enough, or that there might be some timing issues. Here are some things you can try:

Double-check the XPath: Make sure that the XPath you’re using is correct and specific enough. You might want to try using the “Copy XPath” option in the inspect tool to get a more precise XPath.

Wait for the element to be visible: Even if you have waits in place, it’s possible that the element is not yet visible when you try to find it. You can use a wait keyword like Wait Until Element Is Visible to wait for the element to be visible before attempting to interact with it.

Check if the element is inside an iframe: If the element is inside an iframe, you’ll need to switch to the iframe first before trying to find the element. You can use the Switch To Frame keyword for this.

Check if the element is loaded dynamically: If the element is loaded dynamically, you might need to wait for it to be fully loaded before trying to interact with it. You can use a wait keyword like Wait Until Element Contains to wait for the element to contain specific text before attempting to interact with it.

I hope this helps!

Hi Adam,

I’ll use the Highcharts Demos › Basic line as an example.

if you open dev tools on your browser and try the xpath //svg you’ll get no matches dispite there being several svg’s on the path, this is not actually a robot framework issue.

If you try the xpath //div[@id="highcharts-e6w703i-0"] you’ll get the div that holds the svg graph but if you try the xpath //div[@id="highcharts-e6w703i-0"]/svg again no result.

Doing a quick search for “xpath svg not working” you’ll see that lots of people have this issue with Selenium, katalon, and other test tools.

I did also find a solution that might help, the xpath //div[@id="highcharts-e6w703i-0"]/*[local-name()='svg'] does get you the graph on the page above, I don’t know why you need to use the //*[local-name()='svg'] syntax but it seems to work in dev tools and several test tools.

Hope that helps,

Dave.

1 Like