# Clicking on image with Svg format

**URL:** <https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [December 2, 2019, 3:11pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028 "2019-12-02T15:11:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 2, 2019, 3:11pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/1 "2019-12-02T15:11:42Z")

</div>

[HTML.zip](https://europe1.discourse-cdn.com/katalon/original/2X/e/eff3547ed968b1f8951d13fa5d67b45f7394afd6.zip) (3.4 KB)  
Hi,

I am unable to click on an image which has a SVG format (attached full HTML file). Tried the following but it’s throwing an error:

```
                              String expr = '''
                             //*[local-name()="svg"]
                                /*[local-name()="g" and @class="svgZoomPanel"]
                               /*[local-name()="g" and @class="svgDrawingSurface"]
                                  /*[local-name()="g" and @class="svgFixedLayer"]
                                       /*[local-name()="g" and @class="svgShapeLayer"]
                                         /*[local-name()="g" and@class="sapGalileiSymbolLink"]
                                          /*[local-name()="g" and @id="Galilei_ActionSymbol1"]
                                      '''

                                     TestObject tObj = new TestObject()

                                     tObj.addProperty('xpath', ConditionType.EQUALS, expr)

                                     String storefirstvalue = WebUI.click(tObj)

```

Thanks in advance for the help 🙂

BR,  
Saumil

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 2, 2019, 3:27pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/2 "2019-12-02T15:27:23Z")

</div>

Show me a screenshot of the rendered svg element.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 2, 2019, 7:20pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/3 "2019-12-02T19:20:16Z")

</div>

The start of the SVG element is highlighted in blue:

 ![d1](https://europe1.discourse-cdn.com/katalon/original/2X/0/0f6781be2949310a1c207604af51460a3ae26f76.png)

And the tag in concern is highlighted in blue:

 ![d2](https://europe1.discourse-cdn.com/katalon/original/2X/0/07fafce1f1c966e8fc9c28e14197a297b165f517.png)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 2, 2019, 7:50pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/4 "2019-12-02T19:50:36Z")

</div>

Cautionary note: I don’t work with XPath. I work with CSS. Even so, looking at your XPath it looks quite fragile. Long XPath locators and long CSS selectors are inherently fragile - one seemingly minor change to the page and your selector are prone to breakage. That said…

This CSS selector will target the svg element itself:

```auto
#svgRoot-1

```

This will target the `<g>` element:

```auto
#Galilei_ActionSymbol1

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 2, 2019, 10:01pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/6 "2019-12-02T22:01:30Z")

</div>

@saumil.sah

The zip file you attached contained HTML.txt file which contains `<svg>` element only without wrapping `<html>` structure. When I open the HTML.txt file, browser shows the source but can not _render_ the image. Therefore it is impossible for me to reproduce your problem.

Is your Application Under Test publicly accessible? If so, please share the URL.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 2, 2019, 10:51pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/7 "2019-12-02T22:51:08Z")

</div>

Sadly it is not publicly accesssible. Have tried copying the Inner HTML (attached). [HTML.zip](https://europe1.discourse-cdn.com/katalon/original/2X/8/8584f755e1955da1124facb9101aa5c8c1402717.zip) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 3, 2019, 12:22am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/8 "2019-12-03T00:22:38Z")

</div>

Your new zip does not contain `<html>...</html>` markups; it only contains SVG markups. It is not enough. Because the SVG markup detail is not in question. Rather whole HTML markup structure is in question.

Please make a full HTML file which contains your SVG markup so that others can reproduce your problem on their side. For example, on having the page is rendered in your Chrome browser, you can do right-click the page \> Save as … to get the full HTML source.

Unless you provide it, sorry I am not able to look into your problem.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 3, 2019, 3:52pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/9 "2019-12-03T15:52:29Z")

</div>

I am not sure whether the page will be accessible at your end but here is the entire HTML (attached) source

The element that i have to click is:

 ![sendemail](https://europe1.discourse-cdn.com/katalon/original/2X/6/6cac478b022ec40c90f47cd65d3c9b8c79e14a67.png)

[Campaign Designer.html](https://europe1.discourse-cdn.com/katalon/original/2X/b/bd2053736ebe10adf9b7e4c8a55c1dcfcb2d8f30.html) (698.4 KB)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 4, 2019, 8:26am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/10 "2019-12-04T08:26:31Z")

</div>

I could open `Campaign Designer.html` in Chrome browser.  
I could open it in browser launched by Katalon Studio.

I tried to perform some operations on the _SEND EMAIL_ box and got success.

My test case script:

```auto
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import java.nio.file.Path
import java.nio.file.Paths

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path html = projectDir.resolve("Include/fixtures/Campaign Designer.html")
String htmlURL = html.toFile().toURI().toURL().toExternalForm()
WebUI.comment("opening ${htmlURL}")

WebUI.openBrowser('')
WebUI.navigateToUrl(htmlURL)

TestObject to = findTestObject('Campaign Designer/g_Galilei_ActionSymbol1')

WebUI.verifyElementPresent(to, 10)
WebUI.scrollToElement(to, 10)
WebUI.click(to)
WebUI.delay(5)

WebUI.closeBrowser()

```

The Test Object for the _SEND EMAIL_ box:

 ![11](https://europe1.discourse-cdn.com/katalon/original/2X/3/37433d1a1515316602bb6464952af6260bc5418c.jpeg)

I used the following XPath expression — the simplest one worked fine.

```auto
//*[@id="Galilei_ActionSymbol1"]

```

Here I share the project pushished on GitHub:

> **[GitHub - kazurayam/ClickingGraphicsElementInSVG](https://github.com/kazurayam/ClickingGraphicsElementInSVG)**
>
> Contribute to kazurayam/ClickingGraphicsElementInSVG development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 4, 2019, 9:29am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/11 "2019-12-04T09:29:59Z")

</div>

I have already tried similar solutions:

1. Tried with just selecting the xpath attribute:  

2. And then by selecting other attributes:  

The error that i am getting is:

 ![3](https://europe1.discourse-cdn.com/katalon/original/2X/c/c03a33dd9a331f5c3b12b33a28564708a8f5ca12.png)

This is how the element properties look like in my browser when i right click and inspect them (highlighted in blue):

 ![4](https://europe1.discourse-cdn.com/katalon/original/2X/9/959d084d53b5bc1843972baca7bb317e74b96b55.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 4, 2019, 11:17am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/12 "2019-12-04T11:17:09Z")

</div>

Then, what is your question?

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 4, 2019, 11:20am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/13 "2019-12-04T11:20:55Z")

</div>

i am unable to click on the box with the xpath values that i have mentioned. The Spy Web also does not capture the xpath values for the ‘Select Box’. What am i doing wrong here?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 4, 2019, 11:21am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/14 "2019-12-04T11:21:04Z")

</div>

> [@saumil.sah](#):
>
> I have already tried similar solutions:

No, it is not similar at all.

The XPath of your test object is completely different from mine.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 4, 2019, 11:23am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/15 "2019-12-04T11:23:04Z")

</div>

Tried replicating the xpath value that you are using in your test case. Still, getting an error

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 4, 2019, 11:24am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/16 "2019-12-04T11:24:45Z")

</div>

> [@saumil.sah](#):
>
> What am i doing wrong here?

It is a bad idea to rely on the Spy Web tool. Don’t expect it to provide you a complete solution. Especially when the HTML of your Application Under Test is complexed, simply the tool fails to be useful.

And you should study XPath technology and/or CSS Selector technology first. Once you got enough understanding about the XPath/CSS, then the Spy Web tool can be a nice help for you. Without the background knowledge, a GUI tool would be just a puzzle.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 4, 2019, 11:38am UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/17 "2019-12-04T11:38:58Z")

</div>

> [@saumil.sah](#):
>
> Tried replicating the xpath value that you are using in your test case. Still, getting an error

You can create/modify a Test Object manually. Spy tool is just one of the methods to edit Test Objects.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 4, 2019, 2:01pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/18 "2019-12-04T14:01:17Z")

</div>

@saumil.sah

> [@saumil.sah](#):
>
> Still, getting an error

Seriously, _what_ is your problem. You have been given TWO solutions. One by me in CSS and one by @kazurayam in XPath. Apart from syntactic changes, _they are identical_.

Pick one. Get it working (with apologies to John Cleese) “before one of us dies”.

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [December 4, 2019, 3:42pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/19 "2019-12-04T15:42:56Z")

</div>

> [@kazurayam](#):
>
> It is a bad idea to rely on the Spy Web tool

@saumil.sah a bit of added info here:  
spy tool will just ‘guestimate’ and propose some selectors to you, based on internal implemented algorithms (which may change in time) and what can capture on the rendered page (which sometime can be browser dependant)  
You don’te have to trust them blindly, it is just a quick helper.  
study the proposed topics (css vs xpath) and a bit of html basics to understand how to use the selectors properly.

w3schools is a good source for all of above.

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 4, 2019, 4:07pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/20 "2019-12-04T16:07:28Z")

</div>

> [@kazurayam](#):
>
> CSS Selector technology

Until now i used to blindly trust the Spy tool! this was an eye opener. Will keep it in mind 🙂 You are right! i need to update myself with the right way of writing xpath and i guess it’s about time that CSS should be in my learning plans

---

<div class="post-metadata">

**Author:** ![saumil.sah](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/saumil.sah/32/16104_2.png) [@saumil.sah](https://forum.katalon.com/u/saumil.sah)\
**Post date:** [December 4, 2019, 4:08pm UTC](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028/21 "2019-12-04T16:08:44Z")

</div>

Lesson learnt- Not to trust the Spy tool blindly!

I will update with the solution from my end once I am able to understand the xpath behaviour

[Next page](https://forum.katalon.com/t/clicking-on-image-with-svg-format/37028.md?page=2)
