?
Solved

Find the positions of controls on Android

Posted on 2014-07-28
3
Medium Priority
?
227 Views
Last Modified: 2014-07-31
Greetings,
I am working on an automated test framework which should perform some tests on screen by clicking some controls on the
by mean of a screens invoking 'input tap x y', with x,y being the coordinates of the center of the command.
Does anyone have any suggestions on how I can do this ?

Regards,
r
0
Comment
Question by:rjorge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Molnar István
ID: 40224463
iterate through all the controls:

int location[] = new int[2];
for(int i=0; i < layout.getChildCount(); i++) {
    View v = layout.childAt(i);
    if (v instanceof Button) {
        v.getLocationOnScreen(location); 
    }else
    if (v instanceof EditText) {
        ((EditText)v).getLocationOnScreen(location); 
    }
}

Open in new window

in location array you will get the location of button,edittext, etc. , after that  you can show on the screen the coords

hope i understand correctly, your question
ps: sorry, but i didn't have time to test the code, but i think you get the idea
0
 

Author Comment

by:rjorge
ID: 40224501
Hi Molnar,
thanks for the reply. My intention is to (preferably) be able to do it from outside the running app. That way, I don't need to modify it.
Anny suggestion ?
0
 
LVL 13

Accepted Solution

by:
Molnar István earned 2000 total points
ID: 40226888
if you want to test an application, you can use an UI Tester tool called UI Automator Viewer from Google:
UI Tester

with this you can test your application that is running from mobile, it shows you on the right side the coordinates and what you clicked.

for example this application , uses screenshots with some features (it has inspect element)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
These days software publishers make it possible to move all the possible applications on smartphones, tablets, smartwatches, and more. Although behind every logic and decision is a gross doubt: how do they make it possible? In this blog post, we sha…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question