How to get coordinates of a map irrespective of screen resolution

Viewed 188

I am automating a map based( using 'MapBox') web application using Selenium in JAVA .

The map is retrieved as a single image and I have to find the coordinates of different zones in a map.

For this, I have found x&y coordinates and performed click action. But we do have machines of different resolutions to run our scripts.

At this point, coordinates vary and hence incorrect points (zones) are getting clicked.

Please help in handling this issue by generalizing the coordinates irrespective of the machine resolution.

The code used to click on specific coordinates is as below:

Actions action = new Actions(getDriver());
action.moveByOffset(xcordinate, ycordinate).click().build().perform(); //coordinates changes as the resolution changes
1 Answers

This line of code is named wrongly, I think the parameter of the moveByOffset method does not aware of coordinates, it might represent relative pixel position. So you should multiply with a calculated value (coefficient) to provide multi-screen resolution.

action.moveByOffset(xcordinate, ycordinate)
Related