Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonkeyRunner: easy way to determine coordinates for MonkeyDevice touch command?

I've started creating a MonkeyRunner script. This is going ok, but whenever I add a MonkeyDevice::touch command, I have to determine the input coordinates by trial-and-error. Basically I guess at the coordinates I want to touch and see if those coordinates result in the button touch I'm trying to test. That works, but it's a slow process. Is there anyway to determine the coordinates of UI controls, perhaps from the layout XML files?

like image 454
ndnfan Avatar asked Feb 03 '12 20:02

ndnfan


3 Answers

I found how to do it. Use the Pixel Perfect view within Eclipse to determine the x & y coordinates of the UI element. Here's a quick overview: 1) Eclipse must be running 2) Your Android device must be connected (either the real device via ADB, or the emulator) 3) Run the hierarchy viewer (in /tools) 4) Select "Inspect screenshot" The Pixel Perfect view will launch automatically. Just place the cross-hairs on the UI element. The x and y coordinates, along with the RGB values, are displayed below.

Here's the URL that got me started: http://developer.android.com/guide/developing/debugging/debugging-ui.html#pixelperfect

like image 180
ndnfan Avatar answered Nov 03 '22 01:11

ndnfan


This post (monkeyrunner: interacting with views), may give you and idea of how to obtain the View's coordinates using AndroidViewClient.

like image 26
Diego Torres Milano Avatar answered Nov 02 '22 23:11

Diego Torres Milano


Most of the Android versions you can enable pointer location in Settings->Developer Options. Once you enable it, it is easy to find out the (x,y) coordinates.

like image 37
Rilwan Avatar answered Nov 02 '22 23:11

Rilwan