I’d like to click on an object at a specific location. I use below script.
WebUI.clickOffset(testObject, coordX, coordY)
And I got the position of the object with the JavaScript code below.
document.onmousemove = function(e){
var x = e.pageX;
var y = e.pageY;
e.target.title = "X is "+x+" and Y is "+y;
};
Additionally, I set the testObject to the html <body>
element. (I think this part is wrong.)
After setting the coordinate and testobject, when using WebUI.clickOffset, the test appears to click on a strange location.
What’s wrong with the code above?
Thank you for help in solving this problem.
I don’t perceive any issue using the body
element as the TO. However, …
The mouse event pageX
and pageY
properties are relative to the entire document. Was the page scrolled at the time you took the measurements?
The page was not scrolled.
I measured the document size with the code below.
WebUI.getElementHeight(Object to)
WebUI.getElementWidth(Object to)
The code above printed out the size as shown below.
document width : 969 height: 1920
And that’s the code I used.
WebUI.clickOffset(findTestObject('../editor'), 789, 1028)
But This code made below error code.
Caused by: org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move target out of bounds
This error comes even though I put the width and height in smaller than the measured size. Why is that so?
Are you using a portrait monitor? Or am I so tired I can’t envisage that pair of coords?
Oh. That was my mistype.
width: 1920 height: 969
and I didn’t use a portrait monitor…
1 Like
But it still happens out of bounds exception.
WebUI.clickOffset(findTestObject('../editor'), 908, 784)
That coordinate (789,1028) is a wrong code when testing a different location.
I thought I had entered the right position, but the exception occurred from the start.
I found something strange about this problem.
That is my editor page. and I made a test code.
WebUI.clickOffset(findTestObject('../editor'), 0, 0)
Since my object has body element, I think red dot should be clicked. But The test case clicked on the blue dot.
The object created with /html/body appears to be specifying canvas 1 rather than entire document.
I want to click on the coordinates in canvas 2, so out of bounds exception seems to occur.
How do I solve the problem?
I changed testobject to canvas2 and did clickoffset test.
then, Coordinates (0, 0) indicated the center of the canvas, not the top, left of the canvas.
I got the results I wanted, but I don’t understand why the coordinates are like this.