I am trying to click on a svg button and as I understand there is a bit of specificity to do that. My code is as follow but I get an error saying the element is not visible after 5sec:
Click Button When Visible xpath=//
[name()=“svg”]//
[name()=“use”]
image
1072×700 92.9 KB
=> Is it like iframe where we need to select something before being able to interact with the svg button?
Note: I have tried also with click link or click element, but I get the same result
This is the svg button details
image
1530×874 83.4 KB
Thank you
That’s a very odd xpath for selecting that element a more typical xpath would be something like //svg//use (i’ve never seen the use of the
name()
function in an xpath before.
Having said that, I think your “not visible” problem is because that svg image is a part of the button parent and the button is taking the visibility and is what you need to click. Also I notice you are using a “Click Button When Visible” keyword but the element you’ve selected is not a button, so that might be the problem too.
I’d suggest you try something like this:
Click Button When Visible xpath=//button[@title="close"]
Dave.
Hello Dave,
That would be too easy >D.
Click Button When Visible xpath= //svg//use => Element ‘xpath=//svg//use’ not visible after 5 seconds
Click Button When Visible xpath= //button//svg//use => Element ‘xpath=//button//svg//use’ not visible after 5 seconds.
Click Button When Visible xpath= //button [@title,“close”] => Element ‘xpath=//button[@title=“close”]’ not visible after 5 seconds.
Click Button when visible xpath=//button//[name()=‘svg’]//[name()=‘use’] => Button with locator ‘xpath=//button//[name()=‘svg’]//[name()=‘use’]’ not found
Note: only the last attempt return an error message starting with “Button”
If I “inspect” the “X” button to find the selector, it is the <use…> line that’s highlighted.
image1554×616 77.2 KB
I have tried to use the copy xpath selector functionality but as you can see it gives an exception if I check it with document.queryselector image1167×384 29.1 KB
This is why I have started to search for answers about selectors for svg button and I have found this kind of information several times: image1134×847 185 KBimage901×870 44.8 KB
Here is another discussion with info to a very similar case to mine: