How to click at specific coordinates?

Just want to set a mouse click at specific coordinates on page. How do I do this?

There is the command, WebUI.clickOffset(testObject TO, int x offset, int y offset). You can make some formula to calculate where you are to where you want to click. You can use WebUI.findWebElement(testObject) to get a WebElement that can get your current position.

myItem = WebUI.findWebElement(testObject, 10)
WebUI.comment("Current position is ${myItem.getLocation().getX().toString()} and ${myItem.getLocation().getY().toString()}")

I have tried the following WebUI.clickOffset(findTestObject('Object Repository/Button Layers/Layer Views Location Option (Main Building)'),1515 , 445, FailureHandling.STOP_ON_FAILURE) but it seems judging by the output I have to click on an object for this to work, and that is the whole issue I need to click off of an object.

I will give this a try one sec.

Test Cases/FAM/01 FAM DEV/Midwest 037 (DEV)/Plant View Layers FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.findWebElement() is applicable for argument types: (java.lang.String) values: [Object Repository/Button Layers/Layer Views Location Option (Main Building)]```

Ooops. The statement WebUI.findWebElement(testObject, 10) wants a timeOut.

Yeah no such luck. Not sure as to the reason though. I know that this element exists I can use it and interact with it.

Test Cases/FAM/01 FAM DEV/Midwest 037 (DEV)/Plant View Layers FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.findWebElement() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [Object Repository/Button Layers/Layer Views Location Option (Main Building), ...]
Possible solutions: findWebElement(com.kms.katalon.core.testobject.TestObject, int), findWebElement(com.kms.katalon.core.testobject.TestObject), findWebElements(com.kms.katalon.core.testobject.TestObject, int)

Even if I could just send a mouse click to like 2,2 would be useful. I just need to get out of the drawer I am in. Its a full screen overlay and it is making this much harder than it needs to be

For some reason, your TestObject is treated as a String. If the String is the xpath to your TestObject, then you can either go directly to creating a WebElement, such as:

webItem = driver.findElement(By.xpath('your xpath'))
WebUI.comment("Current position is ${webItem.getLocation().getX().toString()} and ${webItem.getLocation().getY().toString()}")

or creating a TestObject and then on to a WebElement.

xpath = 'your pathway String'
TestObject to = new TestObject(xpath)
to.addProperty("xpath", ConditionType.EQUALS, xpath)

myItem = WebUI.findWebElement(to, 10)
WebUI.comment("Current position is ${myItem.getLocation().getX().toString()} and ${myItem.getLocation().getY().toString()}")

I will give it a shot. BTW ever since you suggested this as a way to make TOs I have been using it non stop! Much quicker and way easier on the upkeep. Thank you :slight_smile:

No such driver for class

You probably need the import statements;

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement

WebDriver driver = DriverFactory.getWebDriver();

You can get the import statements needed for your code by using: CTRL + SHIFT + O (oh).

Test Cases/FAM/01 FAM DEV/Midwest 037 (DEV)/Plant View Layers FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: driver for class: Script1669147181992```

Ok I have got it to get the coordinates by running the add.property.

LocationSelection='//mat-option[@id="mat-option-47"]/span'
TestObject to =  new TestObject(LocationSelection)
to.addProperty("xpath",ConditionType.EQUALS,LocationSelection)
myItem = WebUI.findWebElement(to,10)
WebUI.comment("Current position is ${myItem.getLocation().getX()} and ${myItem.getLocation().getY()}")

Current position 1428 and 250

So, if you want to click at location, (2, 2), then subtract the difference:

WebUI.clickOffset(findTestObject('Button Layers/Layer Views Location Option (Main Building)'), -1426 , -443, FailureHandling.STOP_ON_FAILURE)

It might be wise to create a formula of the current position’s X and Y, minus 2 from each, and then put the result in the clickOffset statement.

myItem = WebUI.findWebElement(to,10)
WebUI.comment("Current position is ${myItem.getLocation().getX()} and ${myItem.getLocation().getY()}")

xResult = myItem.getLocation().getX() - 2;
yResult = myItem.getLocation().getY() - 2;

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

WebUI.clickOffset(findTestObject('Button Layers/Layer Views Location Option (Main Building)'), -xResult, -yResult, FailureHandling.STOP_ON_FAILURE)

Thank you, that I will do. Dont know why but it worked the first time around and now it wont so Im back to square one.

Keeps failing at the comment line now

Test Cases/FAM/01 FAM DEV/Midwest 037 (DEV)/Plant View Layers FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: getLocation for class: org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement

How about:

WebUI.comment("Current position is ${myItem.getLocation().getX().toString()} and ${myItem.getLocation().getY().toString()}")

Same issue