# How to click at specific coordinates?

**URL:** <https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041>\
**Category:** Miscellaneous\
**Tags:** start-page\
**Created:** [November 28, 2022, 4:01pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041 "2022-11-28T16:01:40Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![josh.meeks](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.meeks/32/25928_2.png) [@josh.meeks](https://forum.katalon.com/u/josh.meeks)\
**Post date:** [November 28, 2022, 5:53pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/21 "2022-11-28T17:53:39Z")

</div>

No clue why but ran it two more times and it worked this time. Will try adding the variable statement to -2 next.

---

<div class="post-metadata">

**Author:** ![josh.meeks](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.meeks/32/25928_2.png) [@josh.meeks](https://forum.katalon.com/u/josh.meeks)\
**Post date:** [November 28, 2022, 5:56pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/22 "2022-11-28T17:56:27Z")

</div>

> [@grylion54](#):
>
> ```auto
> xResult = myItem.getLocation().getX() - 2;
> yResult = myItem.getLocation().getY() - 2;
> 
> WebUI.comment("Calculated amounts are: ${xResult } and ${yResult}")
> 
> WebUI.clickOffset(findTestObject('Button Layers/Layer Views Location Option (Main Building)'), -xResult, -yResult, FailureHandling.STOP_ON_FAILURE)
> 
> ```

Holy crap yes! It worked! Now I just have to do this about 10 more times and I can make it through these darn options… You are awesome!

---

<div class="post-metadata">

**Author:** ![josh.meeks](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.meeks/32/25928_2.png) [@josh.meeks](https://forum.katalon.com/u/josh.meeks)\
**Post date:** [November 28, 2022, 8:10pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/23 "2022-11-28T20:10:00Z")

</div>

So I am running the same thing for a different object and running into the same issue with the comment not running.

```auto
WebUI.click(findTestObject('Object Repository/Button Layers/Layer Views (Filter To Lines)'))
TestObject to1 = findTestObject('Object Repository/47.) Northern/Layer View Options/Filter Line Selection (Line 1)')
myItem1 = WebUI.findWebElement(to1,10)
WebUI.comment("Current position is ${myItem1.getLocation().getX().toString()} and ${myItem1.getLocation().getY().toString()}")
xResult = myItem1.getLocation().getX() - 1;
yResult = myItem1.getLocation().getY() - 1;

WebUI.comment("Calculated amounts are: ${xResult } and ${yResult}")
WebUI.clickOffset(to1, -xResult, -yResult, FailureHandling.STOP_ON_FAILURE)

```

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [November 28, 2022, 10:45pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/24 "2022-11-28T22:45:10Z")

</div>

> [@josh.meeks](#):
>
> `WebUI.comment("Calculated amounts are: ${xResult } and ${yResult}")`

Again, it’s possible the “integers” don’t set well within the Comment String, so add the toString() onto the integers to resolve the issue.

```auto
WebUI.comment("Calculated amounts are: ${xResult.toString()} and ${yResult.toString() }")

```

---

<div class="post-metadata">

**Author:** ![josh.meeks](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.meeks/32/25928_2.png) [@josh.meeks](https://forum.katalon.com/u/josh.meeks)\
**Post date:** [November 29, 2022, 6:37pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/25 "2022-11-29T18:37:06Z")

</div>

So kinda weird but, it will work either way so long as the case is started from the beginning. If I start anywhere else in the script the comments will fail.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [November 29, 2022, 8:55pm UTC](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041/26 "2022-11-29T20:55:23Z")

</div>

You can either define the variables in the Variable tab or put the Comment statements in a try / catch block with a message like:

```auto
try {
    WebUI.comment("Calculated amounts are: ${xResult.toString()} and ${yResult.toString() }")
} catch (Exception) {
    WebUI.comment("Calculated amounts are: xResult (undefined) and yResult (undefined)")
}

```

The Comment statements are for you and not really needed after you get it working.

[Previous page](https://forum.katalon.com/t/how-to-click-at-specific-coordinates/81041.md?page=1)
