Clicking by Coordintaes

Currently have a webpage that has multiple buttons/icons with exact same id, class, etc…, wondering if there is a way to work around establishing test object and, instead, hard-codes the coordinates I want to click on?

Hi Jolina,

you can (coordinates from top left corner)

WebUI.clickOffset(testObject, coordX, coordY)
1 Like

I was aware of this function, but was confused on how to calculate the coordX and coordY offset values?

Also, in what unit is the offset encoded in?

You can get element coordinates with JavaScript:

document.onmousemove = function(e){
var x = e.pageX;
var y = e.pageY;
e.target.title = "X is "+x+" and Y is "+y;
};

(enter this in dev tools console)

2 Likes

where is code to execute ? in script or keyword ?

Hi everyone,

How to click by coordintaes without element?

Thanks.

Try using the WebUI.clickOffset(testObject, coordX, coordY) method, but set the testObject to the html <body> element.

1 Like

It’s work fine. Thank you!!!

Hi Mate ,

my Test Object is Iframe . i tried to use X and Y Coordinates also …its not working …can u suggest me any best way …??

Thanq

With Regards,
Mikkky…

@mikkili.rahul.tej

Have you switched to Iframe first?

that things already done …tried to other way switch to window index also …but non of them worked.

can able to get in to the Iframe but cannot able to click on the object bec file type hidden.

What exactly is your issue?
What do you mean by “none of them worked”?
Is this even related to clicking by coordinates?
If not, it would be the best if you created a new thread, but first make sure to read this:

Hi Mate,

I am trying to Click on upload text filed which is in Iframe but i cannot able to click.

below is my code

WebUI.mouseOver(findTestObject(‘Object Repository/PipelineProcess/Page_Sales Performance Home/iframe’))
WebUI.mouseOver(findTestObject(‘Object Repository/PipelineProcess/Page_Sales Performance Home/iframe_Supporting Documents _’))
WebUI.click(findTestObject(‘Object Repository/PipelineProcess/Page_Sales Performance Home/input_fileName’))

using X and Y cordinates

WebUI.clickOffset(findTestObject(‘Object Repository/PipelineProcess/Page_Sales Performance Home/input_fileName’), 280, 16)

Thanq
With Regards,
Mikky.

See https://docs.katalon.com/katalon-studio/docs/handling_iframe_issue.html#why-is-it-important-to-know-how-to-test-iframes.

You need to use WebUI.switchToIframe() before interacting with the elements inside of the iframe.

tried already …its not working …

Hi @mikkili.rahul.tej

Please provide the screenshots of the errors, visuals of the page containing the element that you want to click and the console log (copy paste the text in the console tab).

Cheers !

Uploadissue2

Console code
Unable to click on object ‘Object Repository/Page_Sales Performance Home/input_fileName’ using offset x=310 and y=15 (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/PipelineProcess/delete/Page_Sales Performance Home/input_fileName’ located by ‘By.xpath: id(“fileUploadTable”)/tbody[1]/tr[1]/td[1]/input[@class=“file hidden”]’ not found)e[0;39m
2019-08-03 16:34:47.637 e[39mDEBUGe[0;39m e[36mtestcase.UploadFile -e[0;39m e[39m25: delay(20)

Script code …

WebUI.mouseOver(findTestObject(‘Object Repository/Page_Sales Performance Home/iframe’))

WebUI.clickOffset(findTestObject(‘Object Repository/Page_Sales Performance Home/input_fileName’),310,15)

Hi Thanh To ,
Appended as per your request

Thanq…

Are you certain about the coordinates of the objects ? How did you arrive at the coordinates ?

Another approach would be to execute javascript ( see WebUI#executeJavascript documentation).

First you would retrieve element at the coordinate, WebUI#executeJavascript will return a Selenium WebElement if an element at that coordinate exists, then you can use click() method on the WebElement.

Cheers !

Hi Thanh,

Ans1)i tried @Mate_Mrse script to find the coordinates .

Ans2)tried ur way using java script …created a custom keyword and called it in the script .but still having issue .

code

@Keyword

def ClickTO(TestObject to, int timeout) {

WebDriver driver = DriverFactory.getWebDriver();

WebElement element=WebUiCommonHelper.findWebElement(to ,timeout)

JavascriptExecutor executor=((driver)  as JavascriptExecutor)

executor.executeScript('arguements[0].clcik()',element)

}

Script

CustomKeywords.‘keywordPackage.ClickTO.ClickTO’(findTestObject(‘Object Repository/input_fileName’), 60)

Log file error

e[39mTest object with id ‘Object Repository/Pageormance Home/input_fileName’ does not exist

but when the checked the Xpath .its working fine .

kindly suggest any thing i need to change .

log view error

keywordPackage.ClickTO.ClickTO:71

keywordPackage.ClickTO.ClickTO(findTestObject(“Object Repository/PipelineProcess/Page_Sales Performance Home/input_fileName”), 60) FAILED.
Reason:
java.lang.NullPointerException
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:704)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1008)
at com.kms.katalon.core.webui.common.WebUiCommonHelper$findWebElement.call(Unknown Source)
at keywordPackage.ClickTO.ClickTO(ClickTO.groovy:71)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)

Thanq

With Regards,
Mikky.

how to click by coordinates if I’m working on desktop applications?