Solved

Find the positions of controls on Android

Posted on 2014-07-28
3
208 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now