This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 11
Nov 2015

Hi,

I'm automating on a Android Real Device, For an element, the getLocation() API returns the x &y co-ordinates of an element, but when i try to perform actions like tap, swipe, with the co-ordinates which is been fetched from getLocation() API the action does not seem to be performed on expected element.

The co-ordinates fetched through getLocation() API differs from the co-ordinates shown by the Android Devices Pointer Location.

How should tap,swipe be performed based on the elements co-ordinates using TouchActions API.

Kindly provide guidance in the above scenario.

  • created

    Nov '15
  • last reply

    Dec '18
  • 10

    replies

  • 9.1k

    views

  • 7

    users

  • 1

    like

x,y is left upper corner of some element. i suggest first to use element width and height to get element center and tap it instead.

e.g. x+w/2 , y+h/2

Hi
Thanks for your reply.
I did try getting the element size, based on the height and width get the centre position of the element and perform a tap but observed that on android tab screen resolution is different.
should I set any capabilities for screen resolution based on the device type.

Thanks.

"should I set any capabilities for screen resolution based on the device type." - no.

Thanks Aleksei...

Observed that the x and y co-ordinates Appium is fetching is exactly half of the device x and y co-ordinates on android real device.

Please let know the reason....

Try use Values of X and Y values returned by getLocation()
for example
int leftX = element.getLocation().getX();
int rightX = leftX + element.getSize().getWidth();
int middleX = (rightX + leftX) / 2;
int upperY = element.getLocation().getY();
int lowerY = upperY + element.getSize().getHeight();
int middleY = (upperY + lowerY) / 2;

2 years later

C# is not recognizing the getlocation() command.Says that android element does not contain it

1 month later